-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.2.12, 3.4.0
-
Component/s: Aggregation Framework
-
Labels:None
-
ALL
-
The behavior of the "lt" operator in aggregations appears to be that it yields true when comparing any null value to a date. Look at this example:
doc1 : { item : 1, test : new Date(1) } doc2 : { item : 2, test : null }
Scenario 1
find with
{ lt : new Date(100) }
Positive match on doc1 only
aggregate with
{ $lt : [ '$test', new Date(100) ] }
Positive match on both doc1 and doc2
Scenario 2
find with
{ lt : new Date(-1) }
No positive match
aggregate with
{ $lt : [ '$test', new Date(-1) ] }
Positive match on doc2 only
I originally thought that scenario 1 could be explained by the value of null being 0, which is why the aggregate matched doc2. However, I could not think of a reason why doc2 is being matched in scenario 2. I am assuming the difference in behavior between find and aggregate within each scenario is due to the additional checks with find.
This feels like unexpected behavior to me, but please correct me if I am wrong.