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.

Is it possible to get a random document?

default discord avatar
abdullahasad72536 months ago
3

i want to randomise



i am trying to get random documents in batches and would want to not less repeated documents. just like instagram reels

  • discord user avatar
    denolfe
    12 months ago

    Not out of the box, but you could add a custom endpoint to your collection and do some custom logic in it.

    https://payloadcms.com/docs/rest-api/overview#custom-endpoints

    Then use

    req.payload

    with the local API, get totalDoc count, then do something creative with pagination/limit.



    Maybe

    limit: 1

    and

    page: randomIntInTotalDocRange

    Is it possible to get a random document?

  • default discord avatar
    notchr11 months ago

    So the batches themselves should be de-duped?



    You could make a feature request on the repository to add that!

  • default discord avatar
    nomad.dev7 months ago

    Is this still the best way to do it? 🙂 Shouldn't something like

    sort: 'RANDOM()',

    be a nice thing?



    You're right Let's try that! 💪

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.