@@ -21,7 +21,7 @@ assert.commandWorked(coll.insert({_id: 10, a: {b: 1}}));
2121assert . commandWorked ( coll . insert ( { _id : 11 , a : { b : 1 } } ) ) ;
2222
2323/**
24- * Ensures correct results for EQ, LT, LTE, GT, and GTE cases.
24+ * Ensures correct results for EQ, LT, LTE, GT, GTE, and IN cases.
2525 */
2626function testNaNComparisons ( ) {
2727 // EQ
@@ -49,6 +49,33 @@ function testNaNComparisons() {
4949 assert . eq ( 5 , cursor . next ( ) [ "_id" ] ) ;
5050 assert . eq ( 6 , cursor . next ( ) [ "_id" ] ) ;
5151 assert ( ! cursor . hasNext ( ) ) ;
52+
53+ // IN
54+ // Positive NaN should match both positive and negative NaN. Note that the second value protects
55+ // the $in from being optimized away.
56+ cursor = coll . find ( { a : { $in : [ NaN , 1000 ] } } ) . sort ( { _id : 1 } ) ;
57+ assert . eq ( 5 , cursor . next ( ) [ "_id" ] ) ;
58+ assert . eq ( 6 , cursor . next ( ) [ "_id" ] ) ;
59+ assert ( ! cursor . hasNext ( ) ) ;
60+
61+ // Negative NaN should match both positive and negative NaN. Note that the second value protects
62+ // the $in from being optimized away.
63+ cursor = coll . find ( { a : { $in : [ - NaN , 1000 ] } } ) . sort ( { _id : 1 } ) ;
64+ assert . eq ( 5 , cursor . next ( ) [ "_id" ] ) ;
65+ assert . eq ( 6 , cursor . next ( ) [ "_id" ] ) ;
66+ assert ( ! cursor . hasNext ( ) ) ;
67+
68+ // NaNs of different types should match both positive and negative NaN. Note that the second
69+ // value protects the $in from being optimized away.
70+ cursor = coll . find ( { a : { $in : [ NumberDecimal ( NaN ) , 1000 ] } } ) . sort ( { _id : 1 } ) ;
71+ assert . eq ( 5 , cursor . next ( ) [ "_id" ] ) ;
72+ assert . eq ( 6 , cursor . next ( ) [ "_id" ] ) ;
73+ assert ( ! cursor . hasNext ( ) ) ;
74+
75+ cursor = coll . find ( { a : { $in : [ NumberDecimal ( - NaN ) , 1000 ] } } ) . sort ( { _id : 1 } ) ;
76+ assert . eq ( 5 , cursor . next ( ) [ "_id" ] ) ;
77+ assert . eq ( 6 , cursor . next ( ) [ "_id" ] ) ;
78+ assert ( ! cursor . hasNext ( ) ) ;
5279}
5380
5481// Unindexed.
0 commit comments