Recall & Review
beginner
What is a single field index in MongoDB?
A single field index is an index created on one field of a MongoDB collection to speed up queries that filter or sort by that field.
Click to reveal answer
beginner
How do you create a single field index on the field 'age' in MongoDB?
Use the command: <br>
db.collection.createIndex({ age: 1 })<br>Here, 1 means ascending order index.Click to reveal answer
beginner
What does the value 1 or -1 mean when creating a single field index?
1 means the index is created in ascending order, and -1 means descending order. Both speed up queries but may affect sort order.
Click to reveal answer
beginner
Why use a single field index?
It helps MongoDB find documents faster when searching or sorting by that field, improving query performance.
Click to reveal answer
intermediate
Can a single field index speed up queries that filter on multiple fields?
No, single field indexes only help queries filtering or sorting on that one field. For multiple fields, use compound indexes.
Click to reveal answer
Which MongoDB command creates a single field index on 'name' in ascending order?
✗ Incorrect
The correct syntax uses 1 for ascending order: db.collection.createIndex({ name: 1 })
What does the number -1 mean when creating a single field index?
✗ Incorrect
-1 means the index is created in descending order.
Which of these is true about single field indexes?
✗ Incorrect
Single field indexes speed up queries filtering or sorting on that one field.
If you want to speed up queries filtering on two fields, what should you use?
✗ Incorrect
Compound indexes cover multiple fields and speed up queries filtering on those fields.
What happens if you create a single field index on a field that is rarely used in queries?
✗ Incorrect
Indexes help only if queries use that field; otherwise, the index adds overhead without benefit.
Explain what a single field index is and how it helps MongoDB queries.
Think about how an index is like a shortcut to find data faster.
You got /4 concepts.
Describe the difference between using 1 and -1 when creating a single field index.
Consider how sorting can be from smallest to largest or largest to smallest.
You got /4 concepts.