{"record":{"id":"210d23de6c181e82","repo":"microsoft/semantic-kernel","slug":"the-connection-string-is-missing","errorCode":null,"errorMessage":"The connection string is missing.","messagePattern":"The connection string is missing\\.","errorType":"exception","errorClass":"VectorStoreInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/mongodb.py","lineNumber":585,"sourceCode":"                managed_client=managed_client,\n                database_name=database_name or DEFAULT_DB_NAME,\n                embedding_generator=embedding_generator,\n            )\n            if callable(mongo_client.append_metadata):\n                mongo_client.append_metadata(DRIVER_METADATA)\n            return\n\n        try:\n            mongodb_atlas_settings = MongoDBAtlasSettings(\n                env_file_path=env_file_path,\n                connection_string=connection_string,\n                database_name=database_name,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as exc:\n            raise VectorStoreInitializationException(\"Failed to create MongoDB Atlas settings.\") from exc\n        if not mongodb_atlas_settings.connection_string:\n            raise VectorStoreInitializationException(\"The connection string is missing.\")\n\n        mongo_client = AsyncMongoClient(\n            mongodb_atlas_settings.connection_string.get_secret_value(),\n            driver=DRIVER_METADATA,\n        )\n\n        super().__init__(\n            mongo_client=mongo_client,\n            managed_client=managed_client,\n            database_name=mongodb_atlas_settings.database_name,\n            embedding_generator=embedding_generator,\n        )\n\n    @override\n    def get_collection(\n        self,\n        record_type: type[TModel],\n        *,","sourceCodeStart":567,"sourceCodeEnd":603,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/mongodb.py#L567-L603","documentation":"After successfully constructing MongoDBAtlasSettings (validation passed), the constructor checks that a connection string is actually present. If the settings object exists but `connection_string` is falsy (empty or None), this VectorStoreInitializationException is raised. It indicates that settings validation did not fail, but the connection string specifically was not provided — a distinct, more targeted message than the general settings failure.","triggerScenarios":"MongoDBAtlasSettings builds without a ValidationError (e.g. connection_string is an optional field), but the connection_string ends up empty/None. This can happen if connection_string is conditionally required and the settings model allows it to be absent.","commonSituations":"The connection string env var is set to an empty string. A custom settings subclass or env configuration makes connection_string optional at the Pydantic level. The `.env` file exists but the connection string line is blank or commented.","solutions":["Explicitly provide `connection_string` to the MongoDBAtlasStore constructor.","Ensure the `MONGODB_ATLAS_CONNECTION_STRING` environment variable is set to a non-empty value.","Check the `.env` file for a blank or whitespace-only connection string value.","Validate the connection string is non-empty before constructing the store."],"exampleFix":"// before (env var set to empty string)\nstore = MongoDBAtlasStore()\n// after\nstore = MongoDBAtlasStore(connection_string=\"mongodb+srv://user:pass@cluster.mongodb.net\")","handlingStrategy":"validation","validationCode":"import os\nconn = os.getenv(\"MONGODB_ATLAS_CONNECTION_STRING\", \"\")\nif not conn or not conn.strip():\n    raise ValueError(\"Connection string is empty or missing; set MONGODB_ATLAS_CONNECTION_STRING.\")","typeGuard":null,"tryCatchPattern":"try:\n    store = MongoDBAtlasStore()\nexcept VectorStoreInitializationException as e:\n    if \"connection string is missing\" in str(e):\n        # explicitly pass connection_string argument\n        ...","preventionTips":["Always pass connection_string explicitly when not relying solely on env vars.","Check .env files for blank or whitespace-only connection string values.","Validate the connection string is non-empty before constructing the store."],"tags":["mongodb","configuration","connection-string","initialization","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}