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

$multiply operator may return with or w/o an error depending on whether pipeline optimisation is enabled

    • Fully Compatible
    • ALL
    • v4.2, v4.0, v3.6
    • Query 2019-09-09
    • 0

      When pipeline optimization is enabled, the arguments to the $multiply operator can be re-arranged. In certain cases, when one of the arguments is Infinity (or NaN), this re-arrangement may result in an error. But when the pipeline optimization is disabled, the very same query returns without an error.

      For example,

      db.col.insert({num: Infinity})
      db.col.aggregate({$project: {a: {$multiply: [NumberDecimal(1), "$num"]}}})
      2019-08-09T11:32:49.176+0100 E  QUERY    [js] Error: command failed: {
              "ok" : 0,
              "errmsg" : "Can't coerce out of range value inf to long",
              "code" : 31109,
              "codeName" : "Location31109"
      }
      db.adminCommand({configureFailPoint: 'disablePipelineOptimization', mode: 'alwaysOn'})
      db.col.aggregate({$project: {a: {$multiply: [NumberDecimal(1), "$num"]}}})
      { "_id" : ObjectId("5d4d4ba7bf418d2f35ef7d3c"), "a" : NumberDecimal("Infinity") }
      

            Assignee:
            anton.korshunov@mongodb.com Anton Korshunov
            Reporter:
            anton.korshunov@mongodb.com Anton Korshunov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: