Complete the code to list all indexes on the 'users' collection.
db.users.[1]()The listIndexes() method returns all indexes on a collection in MongoDB.
Complete the code to check the current index usage statistics for the 'orders' collection.
db.orders.[1]()The indexStats() method returns statistics about index usage on a collection.
Complete the code to find slow queries that might need indexes in the 'products' collection.
db.[1]({ millis: { $gt: 100 } })
To find slow queries, you query the system.profile collection with find(). The correct syntax is db.system.profile.find({ millis: { $gt: 100 } }). To filter specifically for the 'products' collection, include a condition like { ns: /products$/, millis: { $gt: 100 } } (adjust db name as needed). Here, the blank expects system.profile.find.
Fill both blanks to create an index on the 'email' field in the 'customers' collection to improve query speed.
db.customers.createIndex({ [1]: [2] })To create an ascending index on the 'email' field, use { email: 1 }. The field name is 'email' and the value 1 means ascending order.
Fill all three blanks to create a compound index on 'lastName' (ascending) and 'age' (descending) fields in the 'employees' collection.
db.employees.createIndex({ [1]: [2], [3]: -1 })A compound index is created by specifying multiple fields. Here, 'lastName' is indexed ascending (1), and 'age' descending (-1).