0
0
MongoDBquery~10 mins

Covered queries with indexes in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an index on the 'age' field.

MongoDB
db.users.createIndex([1]: 1})
Drag options to blanks, or click blank then click option'
Aemail
Bname
Cage
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a field not used in the query filter.
Using the wrong field name.
2fill in blank
medium

Complete the query to find users aged 30 using the index.

MongoDB
db.users.find([1]: 30})
Drag options to blanks, or click blank then click option'
Aage
Bemail
Cname
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Filtering by a non-indexed field.
Using a field name that does not exist.
3fill in blank
hard

Fix the error in the index creation by choosing the correct index type for a covered query.

MongoDB
db.users.createIndex([1]: 1})
Drag options to blanks, or click blank then click option'
Aaddress
Bname
Cemail
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using an unrelated field for the index.
Not including the fields needed for the covered query.
4fill in blank
hard

Fill both blanks to create a compound index on 'age' and 'name' for a covered query.

MongoDB
db.users.createIndex([1]: 1, [2]: 1})
Drag options to blanks, or click blank then click option'
Aage
Bemail
Cname
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing fields not used together in queries.
Creating single-field indexes instead of compound.
5fill in blank
hard

Fill all three blanks to write a covered query that uses the compound index on 'age' and 'name' and projects only 'name'.

MongoDB
db.users.find([1]: 25}, [2]: 1, [3]: 0})
Drag options to blanks, or click blank then click option'
Aage
Bname
Cemail
D_id
Attempts:
3 left
💡 Hint
Common Mistakes
Projecting fields not in the index.
Not excluding '_id' when needed for covered queries.