In the list of the APIs provided by Cosmos DB, Microsoft’s globally distributed multi-model database service, the API for MongoDB makes it very easy for the Mongo DB users to migrate to Cosmos DB without much of a hassle. We can communicate with the Cosmos DB’s API for MongoDB using any of the open source MongoDB client drivers. The details about these drivers can be found here: https://docs.mongodb.com/ecosystem/drivers/
The users can enjoy all the functionalities of Mongo DB API with the provided benefits of Cosmos DB like global distribution, automatic indexing, etc.
Features
Cosmos DB’s API for MongoDB is compatible with MongoDB server version 3.2. Any MongoDB features or query operators can be viewed in the Cosmos DB API for MongoDB.
Cosmos DB’s API for MongoDB provides support for MongoDB query language constructs, operations, stages, operators, commands, etc.
Some of the Administration commands are:
- dropDatabase
- listCollections
- drop
- create
- filemd5
- createIndexes
- listIndexes
- dropIndexes
Query and write operation commands:
- findAndModify
- getLastError
- getMore
- insert
- update
As Cosmos DB provides support for Aggregation Pipeline, some of the Aggregation commands are:
- aggregate
- count
- distinct
and Aggregation stages are:
- $skip
- $unwind
- $group
- $sample
- $sort
Example:
{
“ Name”: “Tom”,
“Country”: “United States”,
“Height”: 172,
“Gender”: “Male”,
“Age”: 43,
}
Operators
$exists{ "Age": { $exists: true } }
$eq{ "Name": { $eq: "Tom" } }
$type{ "Age": { $type: "string" } }
and so on.
Conclusion
In this blog post, we saw the different support features of Mongo DB API by Cosmos DB in short. We also saw an example of using the operators on some JSON data.
Leave a Reply