Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

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

default discord avatar
karanbirlast year
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
    generator101last year

    you can't upgrade?

  • default discord avatar
    karanbirlast year

    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
    last year

    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",
      });
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.