Given a MongoDB collection products with an ascending index on price, what will be the order of price values returned by this query?
db.products.find().sort({price: 1})Ascending index means sorting from smallest to largest.
An ascending index on price stores values from lowest to highest. Sorting with {price: 1} uses this index to return documents in ascending order.
Given a MongoDB collection orders with a descending index on orderDate, what will be the order of orderDate values returned by this query?
db.orders.find().sort({orderDate: -1})Descending index means sorting from largest to smallest.
A descending index on orderDate stores values from newest to oldest. Sorting with {orderDate: -1} uses this index to return documents in descending order.
Consider a compound index on {category: 1, price: -1} in a MongoDB collection. Which query will benefit most from this index?
The query must match the index fields and directions to use the index efficiently.
The compound index {category: 1, price: -1} supports queries filtering by category and sorting by price descending. Option B matches both fields and directions.
Which of the following commands correctly creates a descending index on the score field in MongoDB?
Index direction is specified by 1 for ascending or -1 for descending.
The correct syntax uses -1 to specify descending order. Other strings or zero are invalid.
You have a MongoDB collection events with frequent queries sorting by timestamp ascending and some queries sorting by timestamp descending. Which index direction should you choose to optimize overall performance?
MongoDB can scan indexes backward to support opposite sort direction.
Creating an ascending index allows efficient ascending sorts and MongoDB can scan it backward for descending sorts, avoiding extra index creation.