0
0
MongoDBquery~10 mins

createIndex method 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 ascending index on the "name" field.

MongoDB
db.collection.createIndex({ name: [1] })
Drag options to blanks, or click blank then click option'
A1
B-1
C0
D"asc"
Attempts:
3 left
💡 Hint
Common Mistakes
Using -1 instead of 1 for ascending index.
Using 0 which is invalid for index direction.
Using string "asc" which is not accepted.
2fill in blank
medium

Complete the code to create a unique index on the "email" field.

MongoDB
db.users.createIndex({ email: 1 }, { [1]: true })
Drag options to blanks, or click blank then click option'
AexpireAfterSeconds
Bsparse
Cunique
Dbackground
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sparse' which only indexes documents with the field.
Using 'background' which controls index build behavior.
Using 'expireAfterSeconds' which is for TTL indexes.
3fill in blank
hard

Fix the error in the code to create a descending index on the "date" field.

MongoDB
db.events.createIndex({ date: [1] })
Drag options to blanks, or click blank then click option'
Aasc
B0
Cdesc
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings like 'asc' or 'desc' which are invalid.
Using 0 which does not specify direction.
4fill in blank
hard

Fill both blanks to create a TTL index on the "createdAt" field that expires documents after 3600 seconds.

MongoDB
db.logs.createIndex({ createdAt: [1] }, { [2]: 3600 })
Drag options to blanks, or click blank then click option'
A1
BexpireAfterSeconds
Cunique
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using descending index (-1) for TTL which is allowed but less common.
Using 'unique' option which is unrelated to TTL.
5fill in blank
hard

Fill all three blanks to create a compound index on "lastName" (ascending) and "age" (descending) with background building enabled.

MongoDB
db.people.createIndex({ lastName: [1], age: [2] }, { [3]: true })
Drag options to blanks, or click blank then click option'
A1
B-1
Cbackground
Dunique
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'unique' instead of 'background' for the option.
Mixing up ascending and descending values.