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

$add returns null if any of the operands are null

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.4.0
    • Aggregation Framework
    • None
    • MongoDB 2.4.0, Mac OS X 10.8.2
    • ALL
    • Hide

      > db.things.insert({a:2,b:3})
      > db.things.aggregate({$project:{total:{$add:["$a","$b"]}}})
      {
      	"result" : [
      		{
      			"_id" : ObjectId("5148c8d7d2f22a5f45c45d64"),
      			"total" : 5
      		}
      	],
      	"ok" : 1
      }
      > db.things.aggregate({$project:{total:{$add:["$a","$b","$c"]}}})
      {
      	"result" : [
      		{
      			"_id" : ObjectId("5148c8d7d2f22a5f45c45d64"),
      			"total" : null
      		}
      	],
      	"ok" : 1
      }

      Show
      > db.things.insert({a:2,b:3}) > db.things.aggregate({$project:{total:{$add:["$a","$b"]}}}) { "result" : [ { "_id" : ObjectId("5148c8d7d2f22a5f45c45d64"), "total" : 5 } ], "ok" : 1 } > db.things.aggregate({$project:{total:{$add:["$a","$b","$c"]}}}) { "result" : [ { "_id" : ObjectId("5148c8d7d2f22a5f45c45d64"), "total" : null } ], "ok" : 1 }

    Description

      In version 2.2, the aggregation framework $add operator correctly added all non-null operands. In version 2.4, if any one of the operands is null, it returns null.

      Attachments

        Activity

          People

            Unassigned Unassigned
            tdahlke Travis Dahlke
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: