Add delete support for MongoKVStorage

This commit is contained in:
yangdx
2025-03-31 02:14:16 +08:00
parent 078cee390c
commit 5b7cd50005

View File

@@ -150,6 +150,21 @@ class MongoKVStorage(BaseKVStorage):
# Mongo handles persistence automatically
pass
async def delete(self, ids: list[str]) -> None:
"""Delete documents with specified IDs
Args:
ids: List of document IDs to be deleted
"""
if not ids:
return
try:
result = await self._data.delete_many({"_id": {"$in": ids}})
logger.info(f"Deleted {result.deleted_count} documents from {self.namespace}")
except PyMongoError as e:
logger.error(f"Error deleting documents from {self.namespace}: {e}")
async def drop(self) -> dict[str, str]:
"""Drop the storage by removing all documents in the collection.