skip to Main Content

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


  1. Chosen as BEST ANSWER

    I managed to make this work changing my calls to the asyncio library to use async within the library from azure.cosmos.aio import CosmosClient


  2. 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.

    1. Get the MongoDB connection string by using the quick start1.

    2. Install PyMongo using pip2.

    3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search