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
hi @itsjxck - 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,
},
}
]
},
@jesschow 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
Discord
online
Get help straight from the Payload team with an Enterprise License.