How to access Azure Cosmos mongoDB vcore cluster data via python

Priyanka Hurakadli 0 Reputation points Microsoft Employee
2025-02-04T23:36:33.2733333+00:00

I am trying to access Cosmos MongoDB vcore cluster data in my python code. Cluster connection string is mentioned below. I am getting server timeout error. I would also like to know how to use mongdb REST API to read the data.
Connection String:

mongodb+srv://
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,745 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. NIKHILA NETHIKUNTA 4,430 Reputation points Microsoft Vendor
    2025-02-05T07:56:01.18+00:00

    @Priyanka Hurakadli
    Thank you for the question and for using Microsoft Q&A platform.

    As per my understanding you are facing an issue with connecting to your Azure Cosmos DB for MongoDB vCore cluster. Here are a few steps to troubleshoot:

    1. This issue might occur when the cluster doesn't have the correct firewall rules enabled. If you're trying to access the cluster from a non-Azure IP range, you need to add extra firewall rules. https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/troubleshoot-common-issues#unable-to-connect-to-azure-cosmos-db-for-mongodb-vcore---timeout-error
    2. Ensure that you are using a compatible version of the MongoDB driver for your Python code. Sometimes, version mismatches can lead to connection issues.
    3. If you are using environment variables to store your connection string, ensure they are correctly set and accessible in your Python environment.

    MongoDB REST API:

    The Data API for Azure Cosmos DB for MongoDB vCore is an https interface that allows developers to access and interact with their MongoDB vCore data without needing a database driver.

    You can enable or disable this feature using the Azure CLI or an ARM template.
    https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/data-api

    There are also some limitations:

    • Data API works on newly created MongoDB vCore cluster.
    • Data API doesn't support access using reusable access token.
    • Only support aggregate and few other list control plane actions.

    Hope this helps. Do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.