0
0
MongoDBquery~5 mins

Single field index in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Adb.collection.createIndex({ name: 1 })
Bdb.collection.createIndex({ name: 'asc' })
Cdb.collection.createIndex({ name: true })
Ddb.collection.createIndex({ name: 'ascending' })
What does the number -1 mean when creating a single field index?
AIndex in ascending order
BIndex in descending order
CIndex disabled
DIndex on multiple fields
Which of these is true about single field indexes?
AThey speed up queries filtering on one field
BThey speed up queries filtering on multiple fields
CThey slow down queries
DThey are only for sorting, not filtering
If you want to speed up queries filtering on two fields, what should you use?
AText index
BSingle field index
CNo index
DCompound index
What happens if you create a single field index on a field that is rarely used in queries?
AIt will slow down all queries
BIt will always speed up queries
CIt may not improve performance much
DIt deletes documents
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.