Larger document sizes, unique index improvements, $expr support in Azure Cosmos DB API for MongoDB

Shweta Nayak

We are excited to announce these recent updates in Azure Cosmos DB API for MongoDB that enable larger document sizes, improved unique indexes, and expressions in your queries.

 

16MB document support (Preview)

To keep database operations as efficient as possible, it is best practice to keep documents to a small size. This applies to Azure Cosmos DB API for MongoDB as well as MongoDB. However, in some application use cases, larger documents may be required and beneficial.

We’re happy to announce the public preview of 16MB document support in Azure Cosmos DB API for MongoDB. You can sign up for this preview through the Azure portal:

  1. Go to “Preview Features” area in your Azure subscription.
  2. Under “Type”, select “Microsoft.DocumentDB”.
  3. Click on “Azure Cosmos DB API For MongoDB 16MB Document Support” in the list of available preview features.
  4. Click the “Register” button at the bottom of the page to join the preview-

Image 16mbPreview
Screenshot of Azure portal

Learn more about Azure Cosmos DB limits and quotas.

 

Create unique indexes on existing collections (Preview)

Unique indexes enforce uniqueness for the indexed fields and ensure that the fields do not store duplicate values.

Support for unique index on existing collections with data is now available in preview. You can sign up for this preview through the Azure portal:

  1. Go to “Preview Features” area in your Azure subscription.
  2. Under “Type”, select “Microsoft.DocumentDB”.
  3. Click on “Azure Cosmos DB API for MongoDB New Unique Indexes in existing collection” in the list of available preview features.
  4. Click the “Register” button at the bottom of the page to join the preview.

Image uniqueReindexPreview
Screenshot of Azure portal

 

Note that unique index creation on the specified index field(s) will fail if the collection already contains data that would violate the unique constraint. It will also fail if data that violates the unique constraint is added while the index creation is in progress. Index creation may take longer for larger datasets, and we prioritize live user operations over index creation. As a result, a constraint conflict happening while the index creation is in progress will cause the index creation to fail.

You may read more about unique indexes here.

 

Unique partial indexes (General Availability)

With this feature you can specify a partialFilterExpression along with the ‘unique’ constraint in your Azure Cosmos DB API for MongoDB index. This results in the unique constraint being applied only to the documents that meet the specified filter expression.

For example, the following command creates an index on collection books that specifies a unique constraint on the title field and a partial filter expression rating: { $gte: 3 }:

db.books.createIndex(

   { title: 1 },

   { unique: true, partialFilterExpression: { rating: { $gte: 3 } } }

)

The unique constraint will not be effective for documents that do not meet the specified criteria. As a result, other documents will not be prevented from being inserted into the collection.

You may read more about unique partial indexes here.

 

Support for query expressions with $expr (General Availability)

$expr allows the use of aggregation expressions while querying the Azure Cosmos DB API for MongoDB data.

It follows the syntax below:

{ $expr: { <expression> } }

The arguments can be any valid aggregation expression.

Read about supported operators in Azure Cosmos DB API for MongoDB in this doc

1 comment

Leave a comment