0
0
MongoDBquery~5 mins

Index direction (ascending vs descending) in MongoDB - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What does an ascending index mean in MongoDB?
An ascending index sorts the values from smallest to largest (like A to Z or 1 to 10). It helps MongoDB find data quickly in that order.
Click to reveal answer
beginner
What does a descending index mean in MongoDB?
A descending index sorts the values from largest to smallest (like Z to A or 10 to 1). It helps MongoDB find data quickly in reverse order.
Click to reveal answer
beginner
How do you specify an ascending index on the field 'age' in MongoDB?
You create it by using: { age: 1 } where 1 means ascending order.
Click to reveal answer
beginner
How do you specify a descending index on the field 'score' in MongoDB?
You create it by using: { score: -1 } where -1 means descending order.
Click to reveal answer
intermediate
Does the direction of an index (ascending or descending) affect query speed in MongoDB?
No, MongoDB uses indexes efficiently in both ascending and descending directions. The direction mainly affects sorting order, not speed.
Click to reveal answer
In MongoDB, what does the value 1 mean when creating an index on a field?
ANo order
BDescending order
CAscending order
DRandom order
What value do you use to create a descending index on a field in MongoDB?
A-1
B1
C0
D2
If you want to sort query results from highest to lowest using an index, which index direction should you use?
AAscending
BDescending
CEither ascending or descending
DNo index needed
Does MongoDB use ascending indexes to speed up descending sorts?
AYes, but only for single-field indexes
BNo, never
CYes, always
DOnly if the index is compound
Which of these is a valid MongoDB index definition for ascending order on 'name'?
A{ name: -1 }
B{ name: 2 }
C{ name: 0 }
D{ name: 1 }
Explain the difference between ascending and descending index directions in MongoDB and when you might use each.
Think about sorting order and how indexes help find data faster.
You got /5 concepts.
    How do you define an ascending and a descending index on a field in MongoDB? Give the syntax.
    Remember the numbers 1 and -1 represent direction.
    You got /4 concepts.