0
0
MongoDBquery~10 mins

How MongoDB indexes work (B-tree mental model) - Interactive 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 'name' field in a MongoDB collection.

MongoDB
db.collection.createIndex({ name: [1] })
Drag options to blanks, or click blank then click option'
A1
B-1
C0
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 2 as index direction, which are invalid.
Confusing ascending (1) with descending (-1).
2fill in blank
medium

Complete the code to find documents where the 'age' field is greater than 25 using an index.

MongoDB
db.collection.find({ age: { $[1]: 25 } })
Drag options to blanks, or click blank then click option'
Alt
Bne
Ceq
Dgt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt instead of $gt, which finds smaller values.
Using $eq which looks for exact matches.
3fill in blank
hard

Fix the error in the index creation code to ensure it uses a valid B-tree index on 'score'.

MongoDB
db.collection.createIndex({ score: [1] })
Drag options to blanks, or click blank then click option'
A"text"
B2
C1
D"hashed"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 which is invalid for index direction.
Using 'text' or 'hashed' when a B-tree index is needed.
4fill in blank
hard

Fill both blanks to create a compound index on 'lastName' ascending and 'age' descending.

MongoDB
db.collection.createIndex({ lastName: [1], age: [2] })
Drag options to blanks, or click blank then click option'
A1
B-1
C0
D"text"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which is invalid for index direction.
Using 'text' which creates a text index, not a B-tree index.
5fill in blank
hard

Fill all three blanks to create a filtered index on 'status' equals 'active' and sort by 'createdAt' descending.

MongoDB
db.collection.createIndex({ status: [1], createdAt: [2] }, { partialFilterExpression: { status: [3] } })
Drag options to blanks, or click blank then click option'
A1
B-1
C"active"
D"inactive"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong sort directions.
Using 'inactive' instead of 'active' in the filter.