Database / Azure Cosmos DB interview questions
What is Cosmos DB for MongoDB API and what version compatibility does it provide?
The Cosmos DB for MongoDB API is a compatibility layer that implements the MongoDB wire protocol, allowing applications written for MongoDB to connect to Cosmos DB by changing only the connection string. The application code — queries, aggregation pipelines, driver calls — does not change. Cosmos DB parses MongoDB BSON protocol messages and executes them against its own storage engine.
Version compatibility is important to check: Cosmos DB for MongoDB supports several MongoDB server versions (3.2, 3.6, 4.0, 4.2, 5.0, 6.0 as of recent updates). The supported version affects which operators and commands are available. For example, the $lookup aggregation stage (a join-like operation) was added in 3.6, and transactions became available in 4.0. When you create a Cosmos DB for MongoDB account, you select the server version that matches what your application targets.
Key differences from native MongoDB to be aware of in interviews:
- Shard key = partition key — In Cosmos DB for MongoDB, the MongoDB shard key maps to the Cosmos DB partition key. All the same partitioning rules apply: high cardinality, even distribution, immutable after creation.
- Index differences — Cosmos DB for MongoDB creates a wildcard index by default (indexes all fields). In native MongoDB, no indexes are created automatically except for
_id. This means writes to Cosmos DB for MongoDB are slightly more expensive but all fields are queryable without explicit index creation. - Aggregation pipeline support — Not all pipeline stages are supported.
$facet,$graphLookup, and some others have limitations or require specific server version selection. - Sharded transactions — Multi-document transactions are supported but are limited to a single shard (partition), consistent with Cosmos DB's single-partition atomicity model.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
