Equal null can't filter field is not exist on expression

Why can’t I use equal null in expression to filter data that does not exist in the field?

Because it is 2 different conditions. The $exists function exists for this purpose. It is how it is defined.

You are using $expr for an expressive query - in an expressive query there are very different semantics. You can either use a normal query here

 {$match : { jobLevel: null }}

f you woudl need to use where $type == “missing” OR whrre eq null


{ $match : { $expr : { $or : [ { $eq: ["$jobevel":null ]},{
                                 $eq:[{$type:"$jobLevel"},"missing"]}}}

thanks for your reply, the code can solve my problem.

but I cant understand the difference between expressive query and query

Over simplifying what can be found in the documentation:

Normal query

You test a field against a value or expression. For example: { FieldName : { $gt : Value } }. You cannot compare one field against another.

Expressive query

You can have expression on both side of the operators that refers or not to fields. You may compare to fields. Fields value are accessed with $FieldName.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.