{"record":{"id":"3f5e1bd1d9dcb61d","repo":"microsoft/semantic-kernel","slug":"collection-collection-name-not-found","errorCode":null,"errorMessage":"collection {collection_name} not found","messagePattern":"collection (.+?) not found","errorType":"exception","errorClass":"ServiceResourceNotFoundError","httpStatus":404,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/mongodb_atlas/mongodb_atlas_memory_store.py","lineNumber":239,"sourceCode":"        \"\"\"\n        results = self.database[collection_name].find({MONGODB_FIELD_ID: {\"$in\": keys}})\n\n        return [\n            document_to_memory_record(result, with_embeddings) for result in await results.to_list(length=len(keys))\n        ]\n\n    async def remove(self, collection_name: str, key: str) -> None:\n        \"\"\"Removes a memory record from the data store. Does not guarantee that the collection exists.\n\n        Args:\n            collection_name (str): The name associated with a collection of embeddings.\n            key (str): The unique id associated with the memory record to remove.\n\n        Returns:\n            None\n        \"\"\"\n        if not await self.does_collection_exist(collection_name):\n            raise ServiceResourceNotFoundError(f\"collection {collection_name} not found\")\n        await self.database[collection_name].delete_one({MONGODB_FIELD_ID: key})\n\n    async def remove_batch(self, collection_name: str, keys: list[str]) -> None:\n        \"\"\"Removes a batch of memory records from the data store. Does not guarantee that the collection exists.\n\n        Args:\n            collection_name (str): The name associated with a collection of embeddings.\n            keys (List[str]): The unique ids associated with the memory records to remove.\n\n        Returns:\n            None\n        \"\"\"\n        if not await self.does_collection_exist(collection_name):\n            raise ServiceResourceNotFoundError(f\"collection {collection_name} not found\")\n        deletes: list[DeleteOne] = [DeleteOne({MONGODB_FIELD_ID: key}) for key in keys]\n        bulk_write_result = await self.database[collection_name].bulk_write(deletes, ordered=False)\n        logger.debug(\"%s entries deleted\", bulk_write_result.deleted_count)\n","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/mongodb_atlas/mongodb_atlas_memory_store.py#L221-L257","documentation":"Raised as a ServiceResourceNotFoundError in MongoDBAtlasMemoryStore.remove when does_collection_exist returns False. Unlike upsert/get (which do not pre-check), the remove path explicitly guards: it refuses to delete from a non-existent collection.","triggerScenarios":"Calling await store.remove('my_collection', key) when the MongoDB collection does not exist. Note that remove_batch does NOT have this guard (only remove does), so the asymmetry can cause confusion.","commonSituations":"Cleanup code targeting a collection already dropped or never created. Collection name typo. Running remove in an environment where create_collection was never called. Fresh database with no collections.","solutions":["Guard with await store.does_collection_exist(collection_name) before calling remove.","Catch ServiceResourceNotFoundError and treat removal of a missing collection as a no-op.","Verify the collection name and the target database.","Note the asymmetry: remove_batch lacks this check, so prefer remove_batch if idempotent deletion is desired."],"exampleFix":"// before\nawait store.remove('docs', key)  # ServiceResourceNotFoundError\n// after\nif await store.does_collection_exist('docs'):\n    await store.remove('docs', key)\nelse:\n    logging.info('Collection docs absent; skip remove')","handlingStrategy":"validation","validationCode":"async def safe_remove(store, name: str, key: str) -> None:\n    if await store.does_collection_exist(name):\n        await store.remove(name, key)\n    else:\n        logging.info('Collection %s absent; skip remove', name)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceResourceNotFoundError\n\ntry:\n    await store.remove('docs', key)\nexcept ServiceResourceNotFoundError:\n    pass  # collection absent; nothing to remove","preventionTips":["Guard remove with does_collection_exist for idempotent cleanup.","Note the asymmetry: remove_batch lacks this check.","Verify collection name and target database in teardown scripts.","Treat removal of a missing collection as a no-op."],"tags":["mongodb-atlas","collection","resource-not-found","remove","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}