Suggest an editImprove this articleRefine the answer for “How do you sort the result?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)To sort results in MongoDB, use the `sort()` method: it takes an object where the key is the field to sort by and the value is the direction (`1` for ascending, `-1` for descending). **Key point:** you can sort by several fields at once, e.g. `sort({ age: 1, name: -1 })`.Shown above the full answer for quick recall.Answer (EN)ImageTo sort results in MongoDB, use the `sort()` method. ### Example: ```js db.users.find().sort({ age: 1 }) ``` `1` sorts **ascending**, `-1` sorts **descending**. ### A descending example: ```js db.users.find().sort({ age: -1 }) ``` ### The logic: - `sort()` takes an object where the key is the field to sort by, and the value is the direction (`1` or `-1`). - You can sort by several fields at once: ```js db.users.find().sort({ age: 1, name: -1 }) ``` **Summary:** `sort()` changes the order documents come back in, letting you sort by one or several fields, ascending or descending.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.