user1592380
user1592380

Reputation: 36267

Syntax in $or statement

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?

Upvotes: 0

Views: 38

Answers (1)

Yong Shun
Yong Shun

Reputation: 51240

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

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

Upvotes: 2

Related Questions