Get by slug

default discord avatar
3 months ago


I'm trying to setup payload cms to get content by 'slug', eg


However, currently I can only look into one collection at a time, and with content pages, login page and category pages, product page etc, I would love to create a setup where I can go look for the doc once, rather than having to manually check all collections - is this possible?

Thanks 🙂

I currently have this endpoint:

endpoints: [
      path: '/:market?/*',
      method: 'get',
      root: true,
      handler: async (req, res, next) => {
        const market =;
        const slug = req.params[0];
        const docs = await req.payload.find({
          collection: 'pages',
          locale: market,
          where: {
            slug: {
              equals: market ? market + '/' + slug : slug,
        if (!docs || ! || ! {
          return next();
        return res.json([0]);
  • default discord avatar
    3 months ago

    Youre trying to search multiple collections right? I think that's not currently possible due to a mongoose (orm) limitation

    What you can do though is put your


    function into a re-usable async function that takes in a collection parameter, then run it for every collection in your list

    You can get an array of


    promises and resolve them all with

    await Promise.all([])
  • default discord avatar
    3 months ago

    true - I'll do it that way. Thanks

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

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