0
0
MongoDBquery~10 mins

Why advanced indexing matters in MongoDB - Test Your Understanding

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

Complete the code to create a simple index on the 'name' field.

MongoDB
db.collection.createIndex({ name: [1] })
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 causes errors.
Using -1 creates descending index, not ascending.
2fill in blank
medium

Complete the code to create a compound index on 'age' ascending and 'score' descending.

MongoDB
db.collection.createIndex({ age: [1], score: [2] })
Drag options to blanks, or click blank then click option'
Afalse
B-1
Ctrue
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using true or false instead of 1 or -1.
Reversing directions (e.g. -1 for age, 1 for score).
3fill in blank
hard

Fix the error in the index creation by completing the code correctly.

MongoDB
db.collection.createIndex({ [1]: 1 })
Drag options to blanks, or click blank then click option'
Aage
B1
Ctrue
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 or true as the field name key.
Leaving the field name blank.
4fill in blank
hard

Fill both blanks to create a text index on 'description' with unique: true.

MongoDB
db.collection.createIndex({ [1]: 'text' }, { [2]: true })
Drag options to blanks, or click blank then click option'
Adescription
Bunique
Cemail
Dsparse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'email' as the text index field instead of 'description'.
Using 'sparse' instead of 'unique' for uniqueness.
5fill in blank
hard

Fill all three blanks to create a TTL index on 'createdAt' that expires documents after 3600 seconds.

MongoDB
db.collection.createIndex({ [1]: 1 }, { [2]: [3] })
Drag options to blanks, or click blank then click option'
AcreatedAt
BexpireAfterSeconds
C3600
Dunique
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'unique' instead of 'expireAfterSeconds'.
Using wrong field name or missing the expiration value.