I am trying to create a MongoDB database using Azure Cosmos DB in Python, but I encountered some issues and was unsuccessful in the process.
Steps Taken:
Tried creating a new MongoDB database in Azure Cosmos DB using Python.
Followed the documentation for setting up MongoDB on Azure Cosmos DB.
Faced errors during the database creation process.
Tried troubleshooting the issue based on available resources.
Error Message:
2024-04-04 22:43:09 [INFO ] cl_cosmos_mongo_db.py:__mongo_connect - CosmosMongoDB Server Connected.
2024-04-04 22:43:09 [CRITICAL] cl_cosmos_mongo_db.py:__mongo_connect - The user_data database does not exist.
2024-04-04 22:43:09 [INFO ] cl_cosmos_mongo_db.py:__mongo_connect - Creating user_data database.
Arguments: (OperationFailure("Invalid custom action: CreateDatabaseCustomAction specified, full error: {'ok': 0.0, 'errmsg': 'Invalid custom action: CreateDatabaseCustomAction specified', 'code': 59, 'codeName': 'CommandNotFound'}"),)
Expected Behavior:
I expected to successfully create a MongoDB database using Azure Cosmos DB in Python without any errors.
Additional Information:
Successfully connected to Cosmos MongoDB Server
My code:
self.client = MongoClient(self.mongo_uri)
# Test the connection by accessing a database (e.g., admin)
self.client.admin.command('ismaster')
logger.info("CosmosMongoDB Server Connected.")
# Access the database
db = self.client[self.db_name]
# Check if the database exists
db_list = self.client.list_database_names()
if self.db_name in db_list:
logger.info(f"The {self.db_name} database exists.")
else:
logger.critical(f"The {self.db_name} database does not exist.")
logger.info(f"Creating {self.db_name} database.")
db.command({"customAction": "CreateDatabase"})
print("Created db '{}' with shared throughput.\n".format(self.db_name))
@loyal812 This repository is for the Azure database extension in VSCode. You might want to get help at https://github.com/Azure/azure-sdk-for-python. I assume you are using the SDK in your code.
Problem:
I am trying to create a MongoDB database using Azure Cosmos DB in Python, but I encountered some issues and was unsuccessful in the process.
Steps Taken:
Error Message:
Expected Behavior:
I expected to successfully create a MongoDB database using Azure Cosmos DB in Python without any errors.
Additional Information:
My code: