diff --git a/src/item.rs b/src/item.rs index af2acce..0a85175 100644 --- a/src/item.rs +++ b/src/item.rs @@ -471,13 +471,26 @@ impl InventoryCache { .client() .database("cdb") .collection::("cache") - .find_one_and_update(doc! { "_id": "inventory"}, update, options) + .find_one_and_update_with_session(doc! { "_id": "inventory"}, update, options, ses) .await .unwrap(); } - pub async fn remove(uuid: &str) { - // todo : remove from cache + pub async fn remove(uuid: &str, ses: &mut ClientSession) { + let update = doc! { "$pull": { "transactions": uuid}}; + + let options = mongodb::options::FindOneAndUpdateOptions::builder() + .upsert(true) + .return_document(mongodb::options::ReturnDocument::After) + .build(); + + let result = ses + .client() + .database("cdb") + .collection::("cache") + .find_one_and_update_with_session(doc! { "_id": "inventory"}, update, options, ses) + .await + .unwrap(); } }