How do I connect MongoDB and Flask

Azure Cosmos DB API for MongoDB

  • 4 minutes to read

APPLIES TO: Azure Cosmos DB API for MongoDB

The Azure Cosmos DB API for MongoDB makes it easy to use Cosmos DB like a MongoDB database. You can fall back on your MongoDB experience and continue using your favorite MongoDB drivers, SDKs, and tools by referencing your application to the MongoDB account API connection string.

Reasons to Use the API for MongoDB

Since the API for MongoDB is based on Azure Cosmos DB, it offers numerous additional advantages compared to service offerings such as MongoDB Atlas:

  • Immediate scalability: If the auto-scaling feature is activated, your database can be scaled up and down without a warm-up phase.
  • Automatic and transparent sharding: The API for MongoDB takes care of the management of the entire infrastructure for you. Unlike other MongoDB offerings such as MongoDB Atlas, where you have to specify and manage the sharding for horizontal scaling yourself, this includes sharding and the number of shards. This frees up time to focus on developing applications for your users.
  • 99.999 percent availability: You can easily configure 99.999 percent availability to ensure your data is always available.
  • Inexpensive, precise and unlimited scalability: Unlike other MongoDB service offerings, collections can be scaled to any size using shards. MongoDB API users currently use databases with more than 600 TB of storage. Thanks to economies of scale and resource governance, the Cosmos DB platform, in contrast to other MongoDB service offerings, can be cost-effectively scaled in steps of one hundredth of a virtual computer.
  • Serverless deployments: Unlike MongoDB Atlas, the API for MongoDB is a native cloud database with a serverless capacity mode. In serverless mode, billing is purely operation-based and you don't pay for the database when you're not using it.
  • Free tariff: With the free tariff for Azure Cosmos DB, the first 400 RUs / sec. and 5 GB of storage in your account permanently free of charge (applied at the account level).
  • Upgrades in seconds: All API versions are contained in a single code base, which enables version changes with the push of a button and with no downtime.
  • Real-time analysis (HTAP) to any extent: The API for MongoDB enables complex, real-time analytical queries for use cases such as business intelligence based on your database data without affecting your database. Since the cloud-native column-based analysis memory is used without ETL pipelines, this process is quick and inexpensive. You can find more information about Azure Synapse Link here.

How the API works

The Azure Cosmos DB API for MongoDB implements the Wire Protocol for MongoDB. This implementation enables transparent compatibility with native MongoDB client SDKs, drivers, and tools. Azure Cosmos DB does not host the MongoDB database engine. Any MongoDB client driver compatible with the version of API you are using should be able to connect without special configuration.

MongoDB feature compatibility:

The Azure Cosmos DB API for MongoDB is compatible with the following MongoDB server versions:

Because all versions of the API for MongoDB are based on the same code base, upgrades can be easily performed in seconds with no downtime. Azure Cosmos DB simply changes a few feature flags to a different version. The feature flags also enable the continued support of older API versions such as 3.2 and 3.6. You can choose the server version that works best for you.

Important information for getting started

  • You are not billed for virtual machines in a cluster. The prices are based on the throughput in request units (RUs) configured per database or per collection. The first 400 RUs per second are free in the free tariff.

  • The Azure Cosmos DB API for MongoDB can be deployed in three ways:

    • Provisioned Throughput: Set a value for RU / s and change it manually. This model is best for consistent workloads.
    • Autoscaling: Set an upper limit for the required throughput. The throughput is instantly scaled according to your requirements. This model is best suited to workloads that change frequently and optimizes their costs.
    • Serverless (preview): Pay only for the throughput you use. This model is best suited for development / test workloads.
  • The performance of shard clusters depends on the shard key chosen when creating a collection. Choose the shard key carefully to ensure that your data is evenly distributed across shards.

Quick Start

Next Steps

Note: This article describes a feature of Azure Cosmos DB that provides wire protocol compatibility with MongoDB databases. Microsoft does not run MongoDB databases to provide this service. Azure Cosmos DB is not a partner of MongoDB, Inc.