{"id":2233,"date":"2020-12-07T08:54:55","date_gmt":"2020-12-07T16:54:55","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cosmosdb\/?p=2233"},"modified":"2020-12-07T08:54:55","modified_gmt":"2020-12-07T16:54:55","slug":"managing-indexing-azure-portal","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cosmosdb\/managing-indexing-azure-portal\/","title":{"rendered":"Managing indexing through the Azure Portal in Azure Cosmos DB\u2019s API for MongoDB"},"content":{"rendered":"<p>Adding new indexes just got even easier! You can now manage indexing in Azure Cosmos DB\u2019s API for MongoDB accounts directly in the Azure Portal. In this blog, we\u2019ll cover how to add and remove indexes using the new indexing policy editor. We\u2019ll also highlight the differences in best practices for indexing in Azure Cosmos DB\u2019s API for MongoDB and MongoDB.<\/p>\n<p><strong>Navigating to the new indexing policy editor<\/strong><\/p>\n<p>The new indexing policy editor is located within the <strong>Scale &amp; Settings <\/strong>section of the <strong>Data Explorer <\/strong>in all Azure Cosmos DB\u2019s API for MongoDB version 3.6 accounts. If you are using version 3.2, <a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/mongodb-version-upgrade\">here\u2019s our guide for upgrading<\/a>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/indexingMongoNewUX-1.png\"><img decoding=\"async\" class=\"aligncenter wp-image-2243 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/indexingMongoNewUX-1.png\" alt=\"Navigate to new indexing editor\" width=\"1913\" height=\"715\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/indexingMongoNewUX-1.png 1913w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/indexingMongoNewUX-1-300x112.png 300w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/indexingMongoNewUX-1-1024x383.png 1024w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/indexingMongoNewUX-1-768x287.png 768w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/indexingMongoNewUX-1-1536x574.png 1536w\" sizes=\"(max-width: 1913px) 100vw, 1913px\" \/><\/a><\/p>\n<p><strong>Adding indexes<\/strong><\/p>\n<p>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 <strong>Save<\/strong> button in order to apply your changes.\u00a0In this example, it is faster to create the four new indexes if we add them together, as opposed to four separate indexing policy changes.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/addNewIndexes-1.png\"><img decoding=\"async\" class=\"aligncenter wp-image-2246 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/addNewIndexes-1.png\" alt=\"Add new indexes\" width=\"1034\" height=\"693\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/addNewIndexes-1.png 1034w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/addNewIndexes-1-300x201.png 300w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/addNewIndexes-1-1024x686.png 1024w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/addNewIndexes-1-768x515.png 768w\" sizes=\"(max-width: 1034px) 100vw, 1034px\" \/><\/a><\/p>\n<p><strong>Tracking index progress<\/strong><\/p>\n<p>When an index transformation is in-progress, you should wait for the change to complete before making additional changes. You\u2019ll see this banner while an indexing transformation is still in-progress:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/IndexProgressBanner.png\"><img decoding=\"async\" class=\"aligncenter wp-image-2240 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/IndexProgressBanner.png\" alt=\"Index Progress Banner\" width=\"624\" height=\"56\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/IndexProgressBanner.png 624w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/IndexProgressBanner-300x27.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<p><strong>Dropping indexes<\/strong><\/p>\n<p>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 <strong>Save<\/strong> button.<\/p>\n<p><strong> <a href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/dropIndexes-1.png\"><img decoding=\"async\" class=\"aligncenter wp-image-2247 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/dropIndexes-1.png\" alt=\"Drop two indexes\" width=\"1051\" height=\"730\" srcset=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/dropIndexes-1.png 1051w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/dropIndexes-1-300x208.png 300w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/dropIndexes-1-1024x711.png 1024w, https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-content\/uploads\/sites\/52\/2020\/12\/dropIndexes-1-768x533.png 768w\" sizes=\"(max-width: 1051px) 100vw, 1051px\" \/><\/a><\/strong><\/p>\n<p><strong>Understanding the biggest differences between indexing in Azure Cosmos DB\u2019s API for MongoDB and MongoDB<\/strong><\/p>\n<p>While the best indexing best practices in Azure Cosmos DB\u2019s API for MongoDB and MongoDB are similar, there are some key differences:<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"208\"><strong>Concept<\/strong><\/td>\n<td width=\"208\"><strong>Azure Cosmos DB\u2019s API for MongoDB<\/strong><\/td>\n<td width=\"208\"><strong>MongoDB<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"208\">Wildcard indexes<\/td>\n<td width=\"208\">Support multiple fields per query predicate. Query predicates can use a mix of wildcard and non-wildcard indexes.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Best practice:<\/strong> 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.<\/td>\n<td width=\"208\">Support, at most, one field in any given query predicate.<\/p>\n<p>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td width=\"208\">Compound indexes<\/td>\n<td width=\"208\">Only used for sorting query results.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Best practice: <\/strong>If a query predicate filters on multiple fields, create multiple single field indexes. Query predicates can use multiple single field indexes.<\/td>\n<td width=\"208\">Used in most query predicates with multiple fields.<\/td>\n<\/tr>\n<tr>\n<td width=\"208\">Modifying indexing policy<\/td>\n<td width=\"208\">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.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Best practice:<\/strong> 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.<\/p>\n<p>&nbsp;<\/td>\n<td width=\"208\">In MongoDB, each index is logically independent.<\/p>\n<p>&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cosmos-db\/mongodb-indexing\">Learn more about indexing in Azure Cosmos DB\u2019s API for MongoDB<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we\u2019ll cover how to add and remove indexes using the new indexing policy editor. We\u2019ll also highlight the differences in best practices for indexing in Azure Cosmos DB\u2019s API for MongoDB and native MongoDB.<\/p>\n","protected":false},"author":12128,"featured_media":61,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"image","meta":{"_acf_changed":false,"footnotes":""},"categories":[15,14,818],"tags":[],"class_list":["post-2233","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-mongodb-api","category-core-sql-api","category-query","post_format-post-format-image"],"acf":[],"blog_post_summary":"<p>In this blog, we\u2019ll cover how to add and remove indexes using the new indexing policy editor. We\u2019ll also highlight the differences in best practices for indexing in Azure Cosmos DB\u2019s API for MongoDB and native MongoDB.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/2233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/users\/12128"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/comments?post=2233"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/2233\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media\/61"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media?parent=2233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/categories?post=2233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/tags?post=2233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}