0
0
MongoDBquery~10 mins

When not to index 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 in MongoDB.

MongoDB
db.users.createIndex({ age: [1] })
Drag options to blanks, or click blank then click option'
A-1
B1
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using true or false instead of 1 or -1.
Omitting the value for the field.
2fill in blank
medium

Complete the code to drop an index named 'age_1' from the 'users' collection.

MongoDB
db.users.[1]('age_1')
Drag options to blanks, or click blank then click option'
Adrop
BdeleteIndex
CremoveIndex
DdropIndex
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'removeIndex' which does not exist.
Using 'drop' which drops the collection.
3fill in blank
hard

Fix the error in the code to create a text index on the 'description' field.

MongoDB
db.products.createIndex({ description: [1] })
Drag options to blanks, or click blank then click option'
A'text'
Btext
C'Text'
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using text without quotes causes an error.
Using uppercase 'Text' is invalid.
4fill in blank
hard

Fill both blanks to create a compound index on 'category' ascending and 'price' descending.

MongoDB
db.items.createIndex({ category: [1], price: [2] })
Drag options to blanks, or click blank then click option'
A1
B-1
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using true or false instead of 1 or -1.
Using the same value for both fields.
5fill in blank
hard

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

MongoDB
db.records.createIndex({ status: [1], createdAt: [3] }, { partialFilterExpression: { status: [2] } })
Drag options to blanks, or click blank then click option'
A1
B'active'
C-1
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings like 'active' for index directions.
Using 1 instead of -1 for descending.
Confusing partialFilterExpression syntax.