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

Regression of $add aggregation expression behavior with Date type

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Execution
    • ALL
    • Hide

      On 6.1 (master)

      Enterprise test> db.c.insert({})
      {
        acknowledged: true,
        insertedIds: { '0': ObjectId("62e2911b078470e351dec540") }
      }
      Enterprise test> db.c.aggregate(
      ...   [
      ...     { $project: { a: { $add: [  NumberDecimal("9.999999999999999999999999999999999E+6144"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+6144") ] },
      ..... b: { $add: [  NumberDecimal("9.999999999999999999999999999999999E+60"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+60") ] },
      ..... c: { $add: [  NumberDecimal("9.999999999999999999999999999999999E+20"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+20") ] } } }
      ...   ]
      ... )
      [
        {
          _id: ObjectId("62e2911b078470e351dec540"),
          a: ISODate("1970-01-01T00:00:00.000Z"),
          b: ISODate("1970-01-01T00:00:00.000Z"),
          c: ISODate("2019-01-15T06:18:32.992Z")
        }
      ]
      

      On 6.0.

      Enterprise test> db.c.insert({})
      {
        acknowledged: true,
        insertedIds: { '0': ObjectId("62e29c87078470e351dec541") }
      }
      Enterprise test> db.c.aggregate( [ { $project: { a: { $add: [NumberDecimal("9.999999999999999999999999999999999E+6144"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+6144")] }, b: { $add: [NumberDecimal("9.999999999999999999999999999999999E+60"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+60")] }, c: { $add: [NumberDecimal("9.999999999999999999999999999999999E+20"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+20")] } } }])
      [
        {
          _id: ObjectId("62e29c87078470e351dec541"),
          a: ISODate("2019-01-15T06:18:32.992Z"),
          b: ISODate("2019-01-15T06:18:32.992Z"),
          c: ISODate("2019-01-15T06:18:32.992Z")
        }
      ]
      
      Show
      On 6.1 (master) Enterprise test> db.c.insert({}) { acknowledged: true, insertedIds: { '0': ObjectId("62e2911b078470e351dec540") } } Enterprise test> db.c.aggregate( ... [ ... { $project: { a: { $add: [ NumberDecimal("9.999999999999999999999999999999999E+6144"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+6144") ] }, ..... b: { $add: [ NumberDecimal("9.999999999999999999999999999999999E+60"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+60") ] }, ..... c: { $add: [ NumberDecimal("9.999999999999999999999999999999999E+20"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+20") ] } } } ... ] ... ) [ { _id: ObjectId("62e2911b078470e351dec540"), a: ISODate("1970-01-01T00:00:00.000Z"), b: ISODate("1970-01-01T00:00:00.000Z"), c: ISODate("2019-01-15T06:18:32.992Z") } ] On 6.0. Enterprise test> db.c.insert({}) { acknowledged: true, insertedIds: { '0': ObjectId("62e29c87078470e351dec541") } } Enterprise test> db.c.aggregate( [ { $project: { a: { $add: [NumberDecimal("9.999999999999999999999999999999999E+6144"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+6144")] }, b: { $add: [NumberDecimal("9.999999999999999999999999999999999E+60"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+60")] }, c: { $add: [NumberDecimal("9.999999999999999999999999999999999E+20"), ISODate("2019-01-15T06:18:32.992Z"), NumberDecimal("-9.999999999999999999999999999999999E+20")] } } }]) [ { _id: ObjectId("62e29c87078470e351dec541"), a: ISODate("2019-01-15T06:18:32.992Z"), b: ISODate("2019-01-15T06:18:32.992Z"), c: ISODate("2019-01-15T06:18:32.992Z") } ]
    • 135

      $add expression with parameter list [a, d, b], where d is a Date type value and a, b - numeric values, the expression evaluates as (a+d)+b. In the previous version it apparently used to evaluate as (a+b)+d. With large absolute values of a and b and due to limited precision of numeric types the results can differ.

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            mindaugas.malinauskas@mongodb.com Mindaugas Malinauskas
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: