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.

find method of payload with filter by reference

default discord avatar
ivandominguezdomi2 years ago
5

I'm trying to do a custom query in my app built with payload. In this query I filter my Orders collection using the Warehouse collection that are related. I'm trying this way but I can't do it



 const orders = await payload.find({
   collection: 'orders',
   where: {warehouse: {equals:   "640a22cacc1ca5ce8e415958"}},
    page: page,
 });


@here
  • default discord avatar
    jessrynkar2 years ago

    Hey

    @934105872794267648

    - looks like you're on the right path here, are you getting an error when you run this payload.find?



    Also, is your snippet above wrapped with an async function?



    e.g.



    const getOrders = async () => {
      const orders = await payload.find({
        collection: 'orders',
        where: {...},
      });
    
      return orders;
    }
  • default discord avatar
    ivandominguezdomi2 years ago

    Hey

    @854377910689202256


    yes, this is an async function, but it returns an empty array

  • default discord avatar
    jessrynkar2 years ago
    @934105872794267648

    on your

    orders

    collection, is

    warehouse

    a relationship field to another collection?



    and is your access control on the

    orders

    collection set to true?

  • default discord avatar
    ivandominguezdomi2 years ago

    What configuration in access control should I set?

  • default discord avatar
    jessrynkar2 years ago
    read: () => true
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.