From 897d23f917fec560382ffb4f9f30726edd33ba68 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Fri, 3 May 2024 13:40:06 +0200 Subject: [PATCH] work --- src/item.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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(); } }