Complete the code to create a single field index on the 'name' field in MongoDB.
db.collection.createIndex({ [1]: 1 })The code creates an ascending index on the 'name' field. This helps queries that filter or sort by 'name' run faster.
Complete the code to create a descending index on the 'score' field.
db.collection.createIndex({ score: [1] })Using -1 creates a descending index on the 'score' field, which helps queries that sort by score in descending order.
Fix the error in the code to create an index on the 'email' field.
db.collection.createIndex({ [1]: 1 })The field name must be a string in quotes. Using "email" is correct syntax for MongoDB index creation.
Fill both blanks to create an ascending index on the 'username' field with a custom name 'user_index'.
db.collection.createIndex({ [1]: [2] }, { name: "user_index" })The index is created on the 'username' field in ascending order (1). The index is named 'user_index' for easy reference.
Fill all three blanks to create a unique descending index on the 'email' field with the name 'email_unique'.
db.collection.createIndex({ [1]: [2] }, { [3]: true, name: "email_unique" })This creates a unique index on the 'email' field in descending order. The 'unique: true' option enforces uniqueness.