Hi, I am using payload version 1.5.4 , how can i sort my collection by some key

default discord avatar
karanbir
3 months ago
3

In documentation there is a key as defaultSort but its not compatible with 1.5.4 , what will be the alternative

  • default discord avatar
    generator101
    3 months ago

    you can't upgrade?

  • default discord avatar
    karanbir
    3 months ago

    upgrading version will be bit of work , it doesnt seem feasible to upgrade just for a single configuration changes , i was hoping if i could find some alternative

  • discord user avatar
    denolfe
    Payload Team
    2 months ago

    You can pass the

    sort

    property with your query to have it be sorted by that field. And prepend a dash to reverse that order.



    const posts = await payload.find({
        collection: "posts",
        sort: "-createdAt",
      });
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.