| |
read source history
= sort() =
----
[[MongoDB Driver Function Reference]]
Sorts the results.
More information can be found in the corresponding entry of the [[https://docs.mongodb.com/manual/reference/method/db.cursor.sort/index.html|MongoDB Manual]].
[[[@cG
<cursor>.sort(<sort>)
]]]
**Arguments**
[[[@w
|@t0@r0@c0 <cursor> | | The target cursor. |
| <sort> | | A BSON document containing the sort fields. |
]]]
**Returns**
[[[@w
Returns a result set (cursor).
]]]
**Example**
[[[@cw
db.employees.find().sort({ age: 1, salary: -1 });
]]]
Orders all employees ascending by age, then descending by salary.
----
[[Main|home]] | [[MongoDB Driver Function Reference]] | [[MongoDB Driver]]
|