1

Any idea how to represent the following SQL condition for MongoDB

WHERE
     a = 1
AND  b = 2
AND  (c >= 3 OR c IS NULL)
AND  d = 4

Tried this, but seems not working:

{ a:1, b:2, c:{ $in:[ { $gte:3 }, { $exists: false } ] } , d:4 }

This doesn't work since the key 'c' gets overridden:

{ a:1, b:3, $or:[ { c:{ $gte:3 } }, { c:{ $exists:false } } ] , d:4 }

Any help is greatly appreciated

1 Answer 1

4

I think this is what you're looking for:

{ "a": 1, "b": 2, "$or": [ { "c": { "$gte": 3 } }, { "c": { "$exists": false } } ], "d": 4 }

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.