Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-57321

$mod match expression incorrectly handles NaN, Infinity and large values

    • Minor Change
    • ALL
    • v5.0, v4.4, v4.2, v4.0
    • Hide
      db.coll.remove({});
      db.coll.insert({
      		"_id" : 1000907,
      		"obj" : {
      			"obj" : {
      				"num" : NaN,
      			}
      		}
      	});
      db.coll.aggregate([
      	{
      		"$match" : {
      			"obj.obj.num" : {
      				"$mod" : [
      					NumberDecimal("9.999999999999999999999999999999999E+6144"),
      					NumberLong(0)
      				]
      			}
      		}
      	}
      ])
      

      Result:
      Classic: one document in "coll" collection.
      SBE: empty set of documents.

      Show
      db.coll.remove({}); db.coll.insert({ "_id" : 1000907, "obj" : { "obj" : { "num" : NaN, } } }); db.coll.aggregate([ { "$match" : { "obj.obj.num" : { "$mod" : [ NumberDecimal( "9.999999999999999999999999999999999E+6144" ), NumberLong(0) ] } } } ]) Result: Classic: one document in "coll" collection. SBE: empty set of documents.
    • Query Execution 2021-07-12, Query Execution 2021-07-26, QE 2021-09-06
    • 163

      In classic variant of query execution $mod match expression (ModMatchExpression) interprets dividend value NaN (double) as -9223372036854775808 64-bit integer. In SBE, on the other hand, NaN to 64-bit integer transformation results in Nothing.  Furthermore, NumberDecimal("9.999999999999999999999999999999999E+6144") gets interpreted as NumberLong("-9223372036854775808") (classic and SBE). Those two factors, when combined, give unexpected results.  Please see "Steps to Reproduce".

       

            Assignee:
            mihai.andrei@mongodb.com Mihai Andrei
            Reporter:
            mindaugas.malinauskas@mongodb.com Mindaugas Malinauskas
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: