I have an application that uses MongoDB written in Python, and I’m working on migrating it to Azure Cosmos.
I’ve already created an account and prepared a client that I’m reading with
cosmos_client = CosmosClient(url, key)
With this I can connect to the client, but now I want to connect to a Mongodb inside, using its connection string.
So, I’d want something like
mongo_client = cosmos_client.getMongoDatabase(connection_string)
Is there any function to do that? I can’t find anything in the docs
2
Answers
I managed to make this work changing my calls to the
asyncio
library to use async within the libraryfrom azure.cosmos.aio import CosmosClient
I think there is a way to connect to MongoDB in Azure Cosmos DB using Python. You can use the PyMongo driver to communicate with the Azure Cosmos DB’s API for MongoDB.
Get the MongoDB connection string by using the quick start1.
Install PyMongo using pip2.
Use the following code snippet to connect to
your MongoDB instance:
from pymongo import MongoClient
client = MongoClient()
db = client.
You can then use the db object to interact with your MongoDB instance.