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.

Querying a number field that is `null`

default discord avatar
itsjxck2 years ago
2

I have a number field which is optional, and if set and unset gets a

null

value. If I use:


{
  or: [
    {
      numberField: {
        exists: false,
      },
    },
    {
      numberField: {
        equals: null,
      },
    },
  ],
}

it does not match the field.



Is this a bug or is there another way to check if a field specifically has a

null

value? My assumption was that

null

would still match the

exists: false

query

  • default discord avatar
    jessrynkar2 years ago

    hi

    @93699784942034944

    - I replicated your query and it worked correctly for me. Exists>false returned the same docs as equals>null.



    To get the docs that have

    numberField: null

    and not the ones where it is undefined, I used:


    where: {
          and: [
            {
              numberField: {
                equals: null,
              },
            },
            {
              numberField: {
                exists: true,
              },
            }
          ]
        },
  • default discord avatar
    itsjxck2 years ago
    @854377910689202256

    thanks for that; I can confirm it does indeed work when doing this in payload, but in a REST query, it does not work



    I assume this is because

    null

    is not a valid query parameter value



    This behaviour seems strange though, I would expect that a field that has it's values removed, would have the same

    undefined

    value as if the field had never had the value set in the first place

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.