Complete the code to create a simple index on the 'name' field.
db.collection.createIndex({ name: [1] })Using 1 creates an ascending index on the 'name' field, which helps queries sort or filter by name efficiently.
Complete the code to create a compound index on 'age' ascending and 'score' descending.
db.collection.createIndex({ age: [1], score: [2] })Use 1 for ascending and -1 for descending. Here, 'age' is ascending (1) and 'score' is descending (-1).
Fix the error in the index creation by completing the code correctly.
db.collection.createIndex({ [1]: 1 })The field name must be a string key, like 'name'. Using 1 or true as a key causes errors.
Fill both blanks to create a text index on 'description' with unique: true.
db.collection.createIndex({ [1]: 'text' }, { [2]: true })The first blank is the field name for the text index, 'description'. The second blank is the option 'unique' set to true to enforce uniqueness on the index.
Fill all three blanks to create a TTL index on 'createdAt' that expires documents after 3600 seconds.
db.collection.createIndex({ [1]: 1 }, { [2]: [3] })The field to index is 'createdAt'. The option to set TTL is 'expireAfterSeconds', and the value is 3600 seconds (1 hour).