How to query for specific field value in array?

default discord avatar
christian-reichart2 months ago
1 1

So let's say my collection looks something like this:

interface MyCollection {
  myArray: {
    myNumberField: number;
    id?: string;
  }[]
}

I want to get all documents where myNumberField contains a number of [1,2,3]. How would the where query look here? I can't seem to find a solution on https://payloadcms.com/docs/queries/overview#operators

  • Selected Answer
    default discord avatar
    christian-reichart2 months ago

    got it to work, if anyone needs this later:

    where: {
      'myArray.myNumberField': {
        in: [1,2,3]
      }
    }
    
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

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