Home > Net >  Syntax in $or statement
Syntax in $or statement

Time:10-02

enter image description here

I have the following filter which I am trying to test in mongodb compass:

{$or: ["OwedTaxes": {$regex: "$"},"OwedTaxes": {$exists: false}]}

Meaning the OwedTaxes field contains a $ sign or does not exist.

There is a syntax error but I don't understand what it is - What am I doing wrong?

CodePudding user response:

You need to wrap each element in the array with { } curly brace to represent a valid BSON document.

{
  $or: [
    { "OwedTaxes": {$regex: "$"} },
    { "OwedTaxes": {$exists: false} }
  ]
}
  • Related