# How do sort collections by date or id?

**URL:** <https://discourse.getcockpit.com/t/how-do-sort-collections-by-date-or-id/2743>\
**Category:** Uncategorized\
**Created:** [March 23, 2023, 3:01pm UTC](https://discourse.getcockpit.com/t/how-do-sort-collections-by-date-or-id/2743 "2023-03-23T15:01:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oboogy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/oboogy/32/680_2.png) [@oboogy](https://discourse.getcockpit.com/u/oboogy)\
**Post date:** [March 23, 2023, 3:01pm UTC](https://discourse.getcockpit.com/t/how-do-sort-collections-by-date-or-id/2743/1 "2023-03-23T15:01:12Z")

</div>

When fetching collections data using the API how do you sort the collection by one of the fields? The documenation just says this without any examples or references as to what json object should be passed: \* **sort** Url encoded sort json type: json

What would you pass to sort the collection by the date in descending order for example?

 ![Screenshot 2023-03-23 at 11.00.19 AM](https://canada1.discourse-cdn.com/flex030/uploads/getcockpit/original/2X/e/e3b4824ecb64e2b35cf7414d13eb6ad67fb27de9.png)

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [March 23, 2023, 5:31pm UTC](https://discourse.getcockpit.com/t/how-do-sort-collections-by-date-or-id/2743/2 "2023-03-23T17:31:28Z")

</div>

```auto
{_id: 1} // sort by _id asc
{_id: -1} // sort by _id desc

{_id: 1, date:-1} // sort by _id asc + date desc

```
