Final answer:
The $sort stage is used in MongoDB to sort documents in a specified order based on one or more fields.
Step-by-step explanation:
The $sort stage is used in MongoDB, a NoSQL database, to sort documents in a specified order. The stage can be used in aggregation pipelines to rearrange or order the data based on one or more fields. It takes in a set of documents as input and outputs a new set of documents in the specified order.
For example, consider a collection of student records with fields like name, age, and grade. Using the $sort stage, you can sort the records based on the students' names in alphabetical order or based on their age in ascending or descending order.
In summary, the $sort stage in MongoDB allows you to order or rearrange documents in an aggregation pipeline based on specified criteria.