{"record":{"id":"35ad25e8d61a7fd7","repo":"microsoft/semantic-kernel","slug":"failed-to-create-mongodb-atlas-settings","errorCode":null,"errorMessage":"Failed to create MongoDB Atlas settings.","messagePattern":"Failed to create MongoDB Atlas settings\\.","errorType":"exception","errorClass":"MemoryConnectorInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/mongodb_atlas/mongodb_atlas_memory_store.py","lineNumber":70,"sourceCode":"            connection_string (str): The connection string for the MongoDB Atlas instance.\n            database_name (str): The name of the database.\n            read_preference (ReadPreference): The read preference for the connection.\n            env_file_path (str): The path to the .env file containing the connection string.\n            env_file_encoding (str): The encoding of the .env file.\n\n        \"\"\"\n        from semantic_kernel.connectors.mongodb import MongoDBAtlasSettings\n\n        try:\n            mongodb_settings = MongoDBAtlasSettings(\n                database_name=database_name,\n                index_name=index_name,\n                connection_string=connection_string,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as ex:\n            raise MemoryConnectorInitializationError(\"Failed to create MongoDB Atlas settings.\") from ex\n\n        self.mongo_client: motor_asyncio.AsyncIOMotorClient = motor_asyncio.AsyncIOMotorClient(\n            mongodb_settings.connection_string.get_secret_value(),\n            read_preference=read_preference,\n            driver=DriverInfo(\"Microsoft Semantic Kernel\", metadata.version(\"semantic-kernel\")),\n        )\n        self.database_name: str = mongodb_settings.database_name\n        self.index_name: str = mongodb_settings.index_name\n\n    @property\n    def database(self) -> core.AgnosticDatabase:\n        \"\"\"The database object.\"\"\"\n        return self.mongo_client[self.database_name]\n\n    @property\n    def num_candidates(self) -> int:\n        \"\"\"The number of candidates to return.\"\"\"\n        return self.__num_candidates","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/mongodb_atlas/mongodb_atlas_memory_store.py#L52-L88","documentation":"Raised as a MemoryConnectorInitializationError in MongoDBAtlasMemoryStore.__init__ when MongoDBAtlasSettings construction raises a ValidationError. The settings object validates required fields (connection string, database name, index name) from constructor args and/or environment variables; any missing or invalid required field triggers the pydantic ValidationError which is then wrapped here.","triggerScenarios":"Constructing MongoDBAtlasMemoryStore without MONGODB_ATLAS_CONNECTION_STRING / database name / index name in the environment or args. Passing an invalid connection string format. A .env file that is missing or unreadable at the given env_file_path.","commonSituations":"Missing .env file or MONGODB_ATLAS_* env vars in the deployment environment. Typo in the env var name. Connection string lacking required MongoDB Atlas vector search parameters. Running locally without loading the env file.","solutions":["Set the required environment variables: MONGODB_ATLAS_CONNECTION_STRING, MONGODB_ATLAS_DATABASE_NAME, and the index name, or pass them as constructor args.","If using a .env file, verify env_file_path is correct and the file is readable.","Inspect the chained ValidationError (__cause__) for the specific missing/invalid field.","Use MongoDBAtlasSettings() standalone first to surface detailed field-level errors before constructing the store."],"exampleFix":"// before\nstore = MongoDBAtlasMemoryStore()  # MemoryConnectorInitializationError (missing settings)\n// after\n# .env\n# MONGODB_ATLAS_CONNECTION_STRING=mongodb+srv://...\n# MONGODB_ATLAS_DATABASE_NAME=mydb\nstore = MongoDBAtlasMemoryStore(index_name='vector_index')","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.mongodb import MongoDBAtlasSettings\n\ndef validate_mongodb_settings(**kwargs):\n    try:\n        return MongoDBAtlasSettings(**kwargs)\n    except Exception as e:\n        raise ValueError(f'MongoDB Atlas settings invalid: {e}') from e\n\nsettings = validate_mongodb_settings(\n    database_name='mydb', index_name='vector_index', connection_string=conn_str\n)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.memory_connector_exceptions import MemoryConnectorInitializationError\n\ntry:\n    store = MongoDBAtlasMemoryStore(index_name='vector_index')\nexcept MemoryConnectorInitializationError as e:\n    logging.error('MongoDB Atlas settings invalid: %s', e.__cause__)\n    raise","preventionTips":["Set MONGODB_ATLAS_* env vars or pass them as constructor args.","Validate settings standalone first to get field-level error detail.","Verify the .env file path and readability.","Check the connection string format in CI before deployment."],"tags":["mongodb-atlas","settings","initialization","configuration","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}