Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,22 @@ async def delete_documents_async(self, document_ids: List[str]) -> None:
return
await self._collection_async.delete_many(filter={"id": {"$in": document_ids}})

def delete_all_documents(self) -> None:
"""
Deletes all documents in the document store.
"""
self._ensure_connection_setup()
assert self._collection is not None
self._collection.delete_many({})

async def delete_all_documents_async(self) -> None:
"""
Asynchronously deletes all documents in the document store.
"""
await self._ensure_connection_setup_async()
assert self._collection_async is not None
await self._collection_async.delete_many({})

def _embedding_retrieval(
self,
query_embedding: List[float],
Expand Down
12 changes: 12 additions & 0 deletions integrations/mongodb_atlas/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,15 @@ def test_custom_content_field(self):

finally:
database[collection_name].drop()

def test_delete_all_documents(self, document_store: MongoDBAtlasDocumentStore):
docs = [Document(id="1", content="first doc"), Document(id="2", content="second doc")]
document_store.write_documents(docs)
assert document_store.count_documents() == 2
document_store.delete_all_documents()
assert document_store.count_documents() == 0

def test_delete_all_documents_empty_collection(self, document_store: MongoDBAtlasDocumentStore):
assert document_store.count_documents() == 0
document_store.delete_all_documents()
assert document_store.count_documents() == 0
12 changes: 12 additions & 0 deletions integrations/mongodb_atlas/tests/test_document_store_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,15 @@ async def test_delete_documents_async(self, document_store: MongoDBAtlasDocument
assert await document_store.count_documents_async() == 1
await document_store.delete_documents_async(document_ids=["1"])
assert await document_store.count_documents_async() == 0

async def test_delete_all_documents_async(self, document_store: MongoDBAtlasDocumentStore):
docs = [Document(id="1", content="first doc"), Document(id="2", content="second doc")]
await document_store.write_documents_async(docs)
assert await document_store.count_documents_async() == 2
await document_store.delete_all_documents_async()
assert await document_store.count_documents_async() == 0

async def test_delete_all_documents_async_empty_collection(self, document_store: MongoDBAtlasDocumentStore):
assert await document_store.count_documents_async() == 0
await document_store.delete_all_documents_async()
assert await document_store.count_documents_async() == 0