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.

Does anyone know if the Payload API can return multiple items in one request?

default discord avatar
mrl72 years ago
4

E.g. If I want to fetch all pages and all users. Could that be done with one API call?

  • discord user avatar
    jmikrut
    2 years ago

    👍



    ok so there are a few options



    short answer, Payload doesn't do anything like that out of the box



    but longer answer - you could open up a custom endpoint and use a MongoDB

    aggregate

    query that merges content from multiple collections into a single result set



    OR, you could build some type of "search" collection



    take a look at hope network's search functionality:



    https://hopenetwork.org/

    this site uses a collection called

    Search
  • default discord avatar
    mrl72 years ago

    Ok thanks. I will investigate the custom endpoint route with MongoDb.

  • discord user avatar
    jmikrut
    2 years ago

    and then every collection that we want to search across has an

    afterChange

    hook, that syncs it to the

    search

    collection



    so then the frontend of the hope site just queries against the

    search

    collection, and then documents from like 6 collections all get returned



    in a very fast / performant way



    this is good if you just need a quick solution. but another thing to look into, if you are going to be doing heavy searches, and you need it to scale with thousands of docs, is to use Algolia or similar

  • default discord avatar
    mrl72 years ago

    Cool, cheers

    @364124941832159242
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.