In other words, cross-partition queries can still use indexes. It's important to understand that execution is completely independent from index utilization. In this example, the query was executed on four physical partitions. The number of unique shardKeyRangeId values is the number of physical partitions where the query needed to be executed. You can check the shardInformation array to understand the query metrics for each individual physical partition. If you have a large number of provisioned RUs (more than 30,000) or a large amount of data stored (more than approximately 100 GB), you probably have a large enough container to see a significant reduction in query RU charges. Learn more about the differences between in-partition queries and cross-partition queries. This optimization reduces the total number of RUs that the query requires. If your query has an equality filter that matches your container's partition key, you'll need to check only the relevant partition's index. Each physical partition has a separate and independent index. Minimize cross partition queriesĪzure Cosmos DB uses partitioning to scale individual containers as Request Unit and data storage needs increase. If the retrievedDocumentCount is approximately equal to the outputDocumentCount, the query engine didn't have to scan many unnecessary documents. Queries where retrieved document count is equal to Output Document Count Adding an index on version will not improve query performance. In Azure Cosmos DB's API for MongoDB, indexes are not used for the actual aggregation, which in this case is $max. Like in MongoDB, you should place $match as early in the aggregation pipeline as possible to maximize usage of indexes. Adding an index for foodGroup will significantly improve query performance. In this case, indexes can optimize the $match stage. Here is an example that runs a query and uses the $explain command to show query and index usage metrics: In addition to obtaining the RU charge, you should use the $explain command to obtain the query and index usage metrics. As a rough guideline, you should explore ways to lower the RU charge for queries with charges greater than 50 RUs. When you optimize a query in Azure Cosmos DB, the first step is always to obtain the RU charge for your query.
Upgrade to version 3.6 by filing a support request. MongoDB compass aggregate count After that, we will click on Aggregations to apply the aggregation operation. Here, we are using the enterprise collection inside the organisation database. Select the existing database and collection where you want to count the number of documents. Some queries that perform poorly in version 3.2 have significant improvements in versions 3.6+. Open the MongoDB Compass and connect to the server.
db.collection.updateMany() : Update multiple existing documents in the collection.db.collection.updateOne() : Update a single existing document in the collection.db.collection.insertMany() : Insert multiple new documents into the collection.db.collection.insertOne() : Insert a new document into the collection.db.collection.drop() : Drops or removes the collection completely.
db.createCollection() : Creates a new collection.show collections : Prints the list of collections in the current database.
This application may be built using any technology (.NET, Java, PHP, Node, Python, etc), it doesn't matter. You can also connect your own custom application. Behind the scenes, both the Shell and Compass issues the same commands to the database server.
MongoDB Compass is a GUI (Graphical User Interface) for querying, visualizing and modifying database data. We can also use it to perform administrative operations like creating databases, collections etc. MongoDB Shell is an interactive JavaScript interface for querying and modifying database data.