0
0
MongoDBquery~10 mins

Index direction (ascending vs descending) in MongoDB - 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 ascending index on the field 'age'.

MongoDB
db.collection.createIndex({ age: [1] })
Drag options to blanks, or click blank then click option'
A0
B-1
Ctrue
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using -1 instead of 1 for ascending index.
Using 0 or true which are invalid index directions.
2fill in blank
medium

Complete the code to create a descending index on the field 'score'.

MongoDB
db.collection.createIndex({ score: [1] })
Drag options to blanks, or click blank then click option'
A-1
B0
C1
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of -1 for descending index.
Using 0 or boolean values which are invalid.
3fill in blank
hard

Fix the error in the index creation code to specify descending order on 'date'.

MongoDB
db.collection.createIndex({ date: [1] })
Drag options to blanks, or click blank then click option'
A1
B-1
Ctrue
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of -1.
Using boolean or zero values.
4fill in blank
hard

Fill both blanks to create a compound index with 'name' ascending and 'score' descending.

MongoDB
db.collection.createIndex({ name: [1], score: [2] })
Drag options to blanks, or click blank then click option'
A1
B-1
C0
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or true as index directions.
Mixing up ascending and descending values.
5fill in blank
hard

Fill all three blanks to create a compound index with 'category' descending, 'price' ascending, and 'rating' descending.

MongoDB
db.collection.createIndex({ category: [1], price: [2], rating: [3] })
Drag options to blanks, or click blank then click option'
A1
B-1
C0
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or true as index directions.
Confusing ascending and descending values.