Managing indexing through the Azure Portal in Azure Cosmos DB’s API for MongoDB

Tim

Adding new indexes just got even easier! You can now manage indexing in Azure Cosmos DB’s API for MongoDB accounts directly in the Azure Portal. In this blog, we’ll cover how to add and remove indexes using the new indexing policy editor. We’ll also highlight the differences in best practices for indexing in Azure Cosmos DB’s API for MongoDB and MongoDB.

Navigating to the new indexing policy editor

The new indexing policy editor is located within the Scale & Settings section of the Data Explorer in all Azure Cosmos DB’s API for MongoDB version 3.6 accounts. If you are using version 3.2, here’s our guide for upgrading.

Navigate to new indexing editor

Adding indexes

The below example shows how to add three single field indexes (name, age, and address) and one wildcard index (children.$**). In this example, we add four indexes in one single indexing policy change. You must click the Save button in order to apply your changes. In this example, it is faster to create the four new indexes if we add them together, as opposed to four separate indexing policy changes.

Add new indexes

Tracking index progress

When an index transformation is in-progress, you should wait for the change to complete before making additional changes. You’ll see this banner while an indexing transformation is still in-progress:

Index Progress Banner

Dropping indexes

The below example shows how to drop two indexes (address and children.$**). In this example, we drop both indexes in one single indexing policy change. Like when adding indexes, changes are only applied after we click the Save button.

Drop two indexes

Understanding the biggest differences between indexing in Azure Cosmos DB’s API for MongoDB and MongoDB

While the best indexing best practices in Azure Cosmos DB’s API for MongoDB and MongoDB are similar, there are some key differences:

Concept Azure Cosmos DB’s API for MongoDB MongoDB
Wildcard indexes Support multiple fields per query predicate. Query predicates can use a mix of wildcard and non-wildcard indexes.

 

Best practice: Wildcard index performance is equivalent to creating multiple single field indexes. If you are unsure about which indexes to create, try adding a wildcard index for all fields.

Support, at most, one field in any given query predicate.

 

Compound indexes Only used for sorting query results.

 

Best practice: If a query predicate filters on multiple fields, create multiple single field indexes. Query predicates can use multiple single field indexes.

Used in most query predicates with multiple fields.
Modifying indexing policy In Azure Cosmos DB, one single index structure holds references to all indexed fields. Therefore, making many indexing changes together is more efficient than making multiple separate and smaller indexing changes.

 

Best practice: If you need to add multiple new indexes, the indexes will be created more quickly if you add all the indexes together. You should prefer the createIndexes() command over createIndex() since it gives you the ability to add multiple indexes at once.

 

In MongoDB, each index is logically independent.

 

 

Learn more about indexing in Azure Cosmos DB’s API for MongoDB

0 comments

Comments are closed. Login to edit/delete your existing comments