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

$add returns null if any of the operands are null

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.0
    • Component/s: Aggregation Framework
    • None
    • Environment:
      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 }
    • None
    • 0
    • None
    • None
    • None
    • None
    • None
    • None

      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.

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

              Created:
              Updated:
              Resolved: