0
0
MongoDBquery~10 mins

Single field 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 a single field index on the 'name' field in MongoDB.

MongoDB
db.collection.createIndex({ [1]: 1 })
Drag options to blanks, or click blank then click option'
A"email"
B"name"
C"age"
D"address"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong field name.
Forgetting to put the field name in quotes.
2fill in blank
medium

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

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

Fix the error in the code to create an index on the 'email' field.

MongoDB
db.collection.createIndex({ [1]: 1 })
Drag options to blanks, or click blank then click option'
AemailField
Bemail
C'email'
D"email"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the field name.
Using single quotes which may cause errors in some shells.
4fill in blank
hard

Fill both blanks to create an ascending index on the 'username' field with a custom name 'user_index'.

MongoDB
db.collection.createIndex({ [1]: [2] }, { name: "user_index" })
Drag options to blanks, or click blank then click option'
A"username"
B1
C-1
D"user"
Attempts:
3 left
💡 Hint
Common Mistakes
Using -1 instead of 1 for ascending order.
Not quoting the field name.
5fill in blank
hard

Fill all three blanks to create a unique descending index on the 'email' field with the name 'email_unique'.

MongoDB
db.collection.createIndex({ [1]: [2] }, { [3]: true, name: "email_unique" })
Drag options to blanks, or click blank then click option'
A"email"
B-1
Cunique
Dsparse
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to set unique to true.
Using ascending order instead of descending.
Not quoting the field name.