Complete the code to check index usage for a query on the 'users' collection.
db.users.find({ age: { $gt: 25 } }).[1]()The explain() method shows how MongoDB executes a query, including index usage.
Complete the code to get the query planner information from the explain output.
db.orders.find({ status: 'shipped' }).explain().[1]The queryPlanner field in the explain output shows the plan MongoDB uses, including index usage.
Fix the error in the code to correctly check if an index is used for the query on 'products'.
const plan = db.products.find({ price: { $lt: 100 } }).explain().queryPlanner.[1];
print(plan.indexName);The winningPlan inside queryPlanner contains the indexName. Use explain().queryPlanner.winningPlan to access it.
Fill both blanks to create a query that uses explain to check if the 'email' index is used in the 'customers' collection.
const plan = db.customers.find({ [1]: 'example@example.com' }).explain().[2].winningPlan;
print(plan.indexName);The query filters by the 'email' field, and explain().queryPlanner.winningPlan contains the index name.
Fill all three blanks to write code that explains a query on 'inventory' collection, filters by 'category', and prints the index name used.
const plan = db.inventory.find({ [1]: 'electronics' }).explain().[2].[3];
print(plan.indexName);The query filters by 'category'. The explain output's queryPlanner contains the winningPlan which has the indexName.