9. Performance
Activity 9.01: Optimizing a Query
Solution:
Perform the following steps to complete the activity:
- Open your mongo shell and connect to the
sample_supplies
database on the Atlas cluster. First, you need to find how many records the query returns. The following snippet shows acount
query, which gives the number of backpacks sold at the Denver store:Â Â Â Â Â db.sales.count( Â Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â Â "items.name" : "backpack", Â Â Â Â Â Â Â Â Â Â Â Â "storeLocation" : "Denver" Â Â Â Â Â Â Â Â } Â Â Â Â Â ) Â Â Â Â Â
- The query returns a count of
711
records. - Next, analyze the query given by the analytics team using the
explain()
function, and print the execution stats, as...