Azure Cosmos DB for MongoDB (3.2 version) supported features and syntax (2024)

  • Article

APPLIES TO:Azure Cosmos DB for MongoDB (3.2 version) supported features and syntax (1)MongoDB

Azure Cosmos DB is Microsoft's globally distributed multi-model database service. You can communicate with the Azure Cosmos DB for MongoDB using any of the open-source MongoDB client drivers. The Azure Cosmos DB for MongoDB enables the use of existing client drivers by adhering to the MongoDB wire protocol.

By using the Azure Cosmos DB for MongoDB, you can enjoy the benefits of the MongoDB you're used to, with all of the enterprise capabilities that Azure Cosmos DB provides: global distribution, automatic sharding, availability and latency guarantees, automatic indexing of every field, encryption at rest, backups, and much more.

Note

Version 3.2 of the Azure Cosmos DB for MongoDB has no current plans for end-of-life (EOL). The minimum notice for a future EOL is three years.

Protocol Support

All new accounts for Azure Cosmos DB for MongoDB are compatible with MongoDB server version 3.6. This article covers MongoDB version 3.2. The supported operators and any limitations or exceptions are listed below. Any client driver that understands these protocols should be able to connect to Azure Cosmos DB for MongoDB.

Azure Cosmos DB for MongoDB also offers a seamless upgrade experience for qualifying accounts. Learn more on the MongoDB version upgrade guide.

Query language support

Azure Cosmos DB for MongoDB provides comprehensive support for MongoDB query language constructs. Below you can find the detailed list of currently supported operations, operators, stages, commands, and options.

Database commands

Azure Cosmos DB for MongoDB supports the following database commands:

Note

This article only lists the supported server commands and excludes client-side wrapper functions. Client-side wrapper functions such as deleteMany() and updateMany() internally utilize the delete() and update() server commands. Functions utilizing supported server commands are compatible with Azure Cosmos DB for MongoDB.

Query and write operation commands

  • delete
  • find
  • findAndModify
  • getLastError
  • getMore
  • insert
  • update

Authentication commands

  • logout
  • authenticate
  • getnonce

Administration commands

  • dropDatabase
  • listCollections
  • drop
  • create
  • filemd5
  • createIndexes
  • listIndexes
  • dropIndexes
  • connectionStatus
  • reIndex

Diagnostics commands

  • buildInfo
  • collStats
  • dbStats
  • hostInfo
  • listDatabases
  • whatsmyuri

Aggregation pipeline

Aggregation commands

  • aggregate
  • count
  • distinct

Aggregation stages

  • $project
  • $match
  • $limit
  • $skip
  • $unwind
  • $group
  • $sample
  • $sort
  • $lookup
  • $out
  • $count
  • $addFields

Aggregation expressions

Boolean expressions

  • $and
  • $or
  • $not

Set expressions

  • $setEquals
  • $setIntersection
  • $setUnion
  • $setDifference
  • $setIsSubset
  • $anyElementTrue
  • $allElementsTrue

Comparison expressions

  • $cmp
  • $eq
  • $gt
  • $gte
  • $lt
  • $lte
  • $ne

Arithmetic expressions

  • $abs
  • $add
  • $ceil
  • $divide
  • $exp
  • $floor
  • $ln
  • $log
  • $log10
  • $mod
  • $multiply
  • $pow
  • $sqrt
  • $subtract
  • $trunc

String expressions

  • $concat
  • $indexOfBytes
  • $indexOfCP
  • $split
  • $strLenBytes
  • $strLenCP
  • $strcasecmp
  • $substr
  • $substrBytes
  • $substrCP
  • $toLower
  • $toUpper

Array expressions

  • $arrayElemAt
  • $concatArrays
  • $filter
  • $indexOfArray
  • $isArray
  • $range
  • $reverseArray
  • $size
  • $slice
  • $in

Date expressions

  • $dayOfYear
  • $dayOfMonth
  • $dayOfWeek
  • $year
  • $month
  • $week
  • $hour
  • $minute
  • $second
  • $millisecond
  • $isoDayOfWeek
  • $isoWeek

Conditional expressions

  • $cond
  • $ifNull

Aggregation accumulators

  • $sum
  • $avg
  • $first
  • $last
  • $max
  • $min
  • $push
  • $addToSet

Operators

Following operators are supported with corresponding examples of their use. Consider this sample document used in the queries below:

{ "Volcano Name": "Rainier", "Country": "United States", "Region": "US-Washington", "Location": { "type": "Point", "coordinates": [ -121.758, 46.87 ] }, "Elevation": 4392, "Type": "Stratovolcano", "Status": "Dendrochronology", "Last Known Eruption": "Last known eruption from 1800-1899, inclusive"}
OperatorExample
eq{ "Volcano Name": { $eq: "Rainier" } }
gt{ "Elevation": { $gt: 4000 } }
gte{ "Elevation": { $gte: 4392 } }
lt{ "Elevation": { $lt: 5000 } }
lte{ "Elevation": { $lte: 5000 } }
ne{ "Elevation": { $ne: 1 } }
in{ "Volcano Name": { $in: ["St. Helens", "Rainier", "Glacier Peak"] } }
nin{ "Volcano Name": { $nin: ["Lassen Peak", "Hood", "Baker"] } }
or{ $or: [ { Elevation: { $lt: 4000 } }, { "Volcano Name": "Rainier" } ] }
and{ $and: [ { Elevation: { $gt: 4000 } }, { "Volcano Name": "Rainier" } ] }
not{ "Elevation": { $not: { $gt: 5000 } } }
nor{ $nor: [ { "Elevation": { $lt: 4000 } }, { "Volcano Name": "Baker" } ] }
exists{ "Status": { $exists: true } }
type{ "Status": { $type: "string" } }
mod{ "Elevation": { $mod: [ 4, 0 ] } }
regex{ "Volcano Name": { $regex: "^Rain"} }

Notes

In $regex queries, Left-anchored expressions allow index search. However, using 'i' modifier (case-insensitivity) and 'm' modifier (multiline) causes the collection scan in all expressions.When there's a need to include '$' or '|', it's best to create two (or more) regex queries.For example, given the following original query: find({x:{$regex: /^abc$/}), it has to be modified as follows:find({x:{$regex: /^abc/, x:{$regex:/^abc$/}}).The first part will use the index to restrict the search to those documents beginning with ^abc and the second part will match the exact entries.The bar operator '|' acts as an "or" function - the query find({x:{$regex: /^abc|^def/}) matches the documents in which field 'x' has values that begin with "abc" or "def". To utilize the index, it's recommended to break the query into two different queries joined by the $or operator: find( {$or : [{x: $regex: /^abc/}, {$regex: /^def/}] }).

Update operators

Field update operators

  • $inc
  • $mul
  • $rename
  • $setOnInsert
  • $set
  • $unset
  • $min
  • $max
  • $currentDate

Array update operators

  • $addToSet
  • $pop
  • $pullAll
  • $pull (Note: $pull with condition isn't supported)
  • $pushAll
  • $push
  • $each
  • $slice
  • $sort
  • $position

Bitwise update operator

  • $bit

Geospatial operators

OperatorExampleSupported
$geoWithin{ "Location.coordinates": { $geoWithin: { $centerSphere: [ [ -121, 46 ], 5 ] } } }Yes
$geoIntersects{ "Location.coordinates": { $geoIntersects: { $geometry: { type: "Polygon", coordinates: [ [ [ -121.9, 46.7 ], [ -121.5, 46.7 ], [ -121.5, 46.9 ], [ -121.9, 46.9 ], [ -121.9, 46.7 ] ] ] } } } }Yes
$near{ "Location.coordinates": { $near: { $geometry: { type: "Polygon", coordinates: [ [ [ -121.9, 46.7 ], [ -121.5, 46.7 ], [ -121.5, 46.9 ], [ -121.9, 46.9 ], [ -121.9, 46.7 ] ] ] } } } }Yes
$nearSphere{ "Location.coordinates": { $nearSphere : [ -121, 46 ], $maxDistance: 0.50 } }Yes
$geometry{ "Location.coordinates": { $geoWithin: { $geometry: { type: "Polygon", coordinates: [ [ [ -121.9, 46.7 ], [ -121.5, 46.7 ], [ -121.5, 46.9 ], [ -121.9, 46.9 ], [ -121.9, 46.7 ] ] ] } } } }Yes
$minDistance{ "Location.coordinates": { $nearSphere : { $geometry: {type: "Point", coordinates: [ -121, 46 ]}, $minDistance: 1000, $maxDistance: 1000000 } } }Yes
$maxDistance{ "Location.coordinates": { $nearSphere : [ -121, 46 ], $maxDistance: 0.50 } }Yes
$center{ "Location.coordinates": { $geoWithin: { $center: [ [-121, 46], 1 ] } } }Yes
$centerSphere{ "Location.coordinates": { $geoWithin: { $centerSphere: [ [ -121, 46 ], 5 ] } } }Yes
$box{ "Location.coordinates": { $geoWithin: { $box: [ [ 0, 0 ], [ -122, 47 ] ] } } }Yes
$polygon{ "Location.coordinates": { $near: { $geometry: { type: "Polygon", coordinates: [ [ [ -121.9, 46.7 ], [ -121.5, 46.7 ], [ -121.5, 46.9 ], [ -121.9, 46.9 ], [ -121.9, 46.7 ] ] ] } } } }Yes

Sort Operations

When you use the findOneAndUpdate operation, sort operations on a single field are supported, but sort operations on multiple fields aren't supported.

Other operators

OperatorExampleNotes
$all{ "Location.coordinates": { $all: [-121.758, 46.87] } }
$elemMatch{ "Location.coordinates": { $elemMatch: { $lt: 0 } } }
$size{ "Location.coordinates": { $size: 2 } }
$comment{ "Location.coordinates": { $elemMatch: { $lt: 0 } }, $comment: "Negative values"}
$textNot supported. Use $regex instead.

Unsupported operators

The $where and the $eval operators aren't supported by Azure Cosmos DB.

Methods

Following methods are supported:

Cursor methods

MethodExampleNotes
cursor.sort()cursor.sort({ "Elevation": -1 })Documents without sort key don't get returned

Unique indexes

Azure Cosmos DB indexes every field in documents that are written to the database by default. Unique indexes ensure that a specific field doesn't have duplicate values across all documents in a collection, similar to the way uniqueness is preserved on the default _id key. You can create custom indexes in Azure Cosmos DB by using the createIndex command, including the 'unique' constraint.

Unique indexes are available for all Azure Cosmos DB accounts using Azure Cosmos DB for MongoDB.

Time-to-live (TTL)

Azure Cosmos DB only supports a time-to-live (TTL) at the collection level (_ts) in version 3.2. Upgrade to versions 3.6+ to take advantage of other forms of TTL.

User and role management

Azure Cosmos DB doesn't yet support users and roles. However, Azure Cosmos DB supports Azure role-based access control (Azure RBAC) and read-write and read-only passwords/keys that can be obtained through the Azure portal (Connection String page).

Replication

Azure Cosmos DB supports automatic, native replication at the lowest layers. This logic is extended out to achieve low-latency, global replication as well. Azure Cosmos DB doesn't support manual replication commands.

Write Concern

Some applications rely on a Write Concern that specifies the number of responses required during a write operation. Due to how Azure Cosmos DB handles replication in the background all writes are automatically Quorum by default. Any write concern specified by the client code is ignored. Learn more in Using consistency levels to maximize availability and performance.

Sharding

Azure Cosmos DB supports automatic, server-side sharding. It manages shard creation, placement, and balancing automatically. Azure Cosmos DB doesn't support manual sharding commands, which means you don't have to invoke commands such as shardCollection, addShard, balancerStart, moveChunk etc. You only need to specify the shard key while creating the containers or querying the data.

Next steps

  • Learn how to use Studio 3T with Azure Cosmos DB for MongoDB.
  • Learn how to use Robo 3T with Azure Cosmos DB for MongoDB.
  • Explore MongoDB samples with Azure Cosmos DB for MongoDB.
Azure Cosmos DB for MongoDB (3.2 version) supported features and syntax (2024)

FAQs

What are the features of Cosmos DB for MongoDB? ›

Security Controls
MongoDBMicrosoft Cosmos DB Emulation API
Encryption of data at-restYesYes
Client-side field level encryption Encryption of data in-use. Data not readable by service providerYesNo
Queryable Encryption Data encrypted on the client side can be queried without decryption.YesNo
LDAP IntegrationYesYes
5 more rows

What version of MongoDB is Cosmos DB? ›

Azure Cosmos DB supports MongoDB v4. 2, or MongoDB v5. 0 for vCore clusters.

What is Azure Cosmos DB and what are its features? ›

Azure Cosmos DB is a global distributed, multi-model database that is used in a wide range of applications and use cases. It is a good choice for any serverless application that needs low order-of-millisecond response times, and needs to scale rapidly and globally.

What is the difference between MongoDB and Cosmos DB Azure? ›

Cosmos DB offers global scalability and automatic multi-region replication, ideal for low latency and high availability. MongoDB provides horizontal scalability through sharding. Cosmos DB is a fully managed service handling administrative tasks, while MongoDB can be self-hosted or used as a managed service.

What are the main features of MongoDB? ›

Let's take a look at MongoDB's top five technical features:
  • Ad-hoc queries for optimized, real-time analytics. ...
  • Indexing appropriately for better query executions. ...
  • Replication for better data availability and stability. ...
  • Sharding. ...
  • Load balancing.

What is the difference between Azure DB and Cosmos DB? ›

Azure SQL is based on SQL Server engine, you can easily migrate applications and continue to use the tools, languages, and resources that you're familiar with. Azure Cosmos DB is used for web, mobile, gaming, and IoT application that needs to handle massive amounts of data, reads, and writes at a global scale.

How to check the MongoDB version in Azure? ›

Sign into the Azure portal. Navigate to your Azure Cosmos DB for MongoDB account. Open the Overview pane and verify that your current Server version is either 3.2 or 3.6.

Which MongoDB version is best? ›

MongoDB 8.0 is the easiest way to future-proof your application for the next stage of growth. Key features include: Sharding configuration servers can be embedded in sharded clusters, which simplifies the architecture and lowers the overall infrastructure cost without impacting scale and performance.

How to connect MongoDB to Azure Cosmos DB? ›

Get the MongoDB connection string by using the quick start
  1. In an Internet browser, sign in to the Azure portal.
  2. In the Azure Cosmos DB pane, select the API.
  3. In the left pane of the account pane, select Quick start.
  4. Choose your platform (. NET, Node. ...
  5. Copy and paste the code snippet into your MongoDB app.

What are the special features of cosmos? ›

Cosmos can grow up to 1.50m tall and the double pinnate flowers grow from its long stems. In the species Cosmos bipinnatus, which is common in Europe, Cosmos means beauty and bipinnatus leafy. Its delicate flowers are pink to purple or completely white with a diameter of about 10 cm.

What are the requirements for Azure Cosmos DB? ›

An Azure Cosmos DB container (or shared throughput database) using manual throughput must have a minimum throughput of 400 RU/s. As the container grows, Azure Cosmos DB requires a minimum throughput to ensure the resource (database or container) has sufficient resource for its operations.

Which items are supported with Azure Cosmos DB? ›

APIs in Azure Cosmos DB

Azure Cosmos DB offers multiple database APIs, which include NoSQL, MongoDB, PostgreSQL, Cassandra, Gremlin, and Table. By using these APIs, you can model real world data using documents, key-value, graph, and column-family data models.

Which databases are supported by Azure Cosmos DB? ›

Choose from multiple database APIs including the native API for NoSQL, MongoDB, PostgreSQL, Apache Cassandra, Apache Gremlin, and Table. Use Azure Cosmos DB as your unified AI database for data models like relational, document, vector, key-value, graph, and table.

How to use MongoDB in Azure? ›

How do I access MongoDB on Azure? Once you have deployed your MongoDB cluster on Azure, either by using MongoDB Atlas or creating a self-managed cluster, use the cluster's connection string to access either from the command line or through a MongoDB driver in your language of choice.

What is the maximum database size for Azure Cosmos DB? ›

- Maximum storage per Cosmos DB account: 20 TB (soft limit, can be increased upon request). - Maximum request unit (RU) per second for a single partition key value: 10,000 RU/s for dedicated throughput containers and 4,000 RU/s for shared throughput containers.

What is Azure Cosmos DB for MongoDB RBAC? ›

Azure Cosmos DB for MongoDB exposes a built-in role-based access control (RBAC) system that lets you authorize your data requests with a fine-grained, role-based permission model. Users and roles reside within a database and are managed using the Azure CLI, Azure PowerShell, or Azure Resource Manager (ARM).

What features are uniquely available in MongoDB Atlas? ›

MongoDB Atlas
Multi-statement distributed ACID transactionsYes
Integrated text search, geospatial processing, graph traversalsYes All available from a single API and platform
Native support for time series dataYes
Hedged Reads Queries submitted to multiple replicas for consistent low latencyYes
20 more rows

How to connect Azure Cosmos DB for MongoDB? ›

Follow the below steps:
  1. In an Internet browser, sign in to the Azure portal.
  2. In the Azure Cosmos DB pane, select the API.
  3. In the left pane of the account pane, select Quick start.
  4. Choose your platform (. NET, Node. js, MongoDB Shell, Java, Python). ...
  5. Copy and paste the code snippet into your MongoDB app.

What are the characteristics of a Cosmos DB access key? ›

In this article
Access control typeCharacteristics
Primary/secondary keysShared secret allowing any management or data operation. It comes in both read-write and read-only variants.
Role-based access control (RBAC)Fine-grained, role-based permission model using Microsoft Entra identities for authentication.
1 more row
Aug 14, 2024

Top Articles
How To Get The Best Money Market Account Rate | Bankrate
Money Market Account (MMA) - Overview, How It Works
Craigslist Apartments For Rent Cheap
Harry Potter Magic Awakened best cards tier list – July 2023
Victoria Tortilla & Tamales Factory Menu
80 For Brady Showtimes Near Cinemark At Harlingen
Costco Fuel Price Today Near Me
Cmx Cinemas Gift Card Balance
8x20, 8x40 Shipping containers storage container for rent or sale - general for sale - by dealer - craigslist
True Or False Security Is A Team Effort
Pulitzer And Tony Winning Play About A Mathematical Genius Crossword
102 Weatherby Dr Greenville Sc 29615
Endocriene systeemklieren
Best Pedicure Nearby
Integrations | Information Technology
Tyreek Hill admits some regrets but calls for officer who restrained him to be fired | CNN
Premier Auto Works-- The House Of Cash Car Deals
Zitobox Tips And Tricks
Rugged Gentleman Barber Shop Martinsburg Wv
Summoner Weapons Terraria
Dupage County Fcrc
NFL Week 1 coverage map: Full TV schedule for CBS, Fox regional broadcasts | Sporting News
Waitlistcheck Sign Up
Dishonored Subreddit
Dayinew
Bilt Rent Day Challenge June 2023 Answers
Webmail.unt.edu
Management Trainee: Associate Adjuster - June 2025
Fedex Passport Locations Near Me
Ny Trapping Forum
Does Walmart have Affirm program? - Cooking Brush
Grand Forks (British Columbia) – Travel guide at Wikivoyage
Rachel Pizzolato Age, Height, Wiki, Net Worth, Measurement
Walmart Front Door Wreaths
Dallas College Radiology Packet
Bianca Censo
Rubmd.com.louisville
[PDF] Canada - Free Download PDF
Personapay/Glens Falls Hospital
Disney Immersive Experience Cleveland Discount Code
Tses Orts.com
Extraordinary Life: He Was A Feminist, Concerned With Power And Privilege
AI Packgod Roast Generator [100% Free, No Login Required]
Computer Repair Arboretum North Carolina
Ava Kayla And Scarlet - Mean Bitches Humiliate A Beta
Ascensionpress Com Login
Trapshooters.com Discussion Forum
Dollar General Penny List July 18 2023
Sharon Sagona Obituary
Papitop
Bookoo Garage Sales
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 6565

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.