Skip to content

Instantly share code, notes, and snippets.

@travisdahlke
Created March 19, 2013 20:11
Show Gist options
  • Save travisdahlke/5199641 to your computer and use it in GitHub Desktop.
Save travisdahlke/5199641 to your computer and use it in GitHub Desktop.
Mongo 2.4 $add nulls test
use agg_test;
test_add = function() {
var t = db.things;
t.drop();
t.insert({a: 2, b: 3});
var total1 = t.aggregate({$project:{total:{$add:["$a","$b"]}}}).result[0].total;
print("a + b = " + total1);
var total2 = t.aggregate({$project:{total:{$add:["$a","$b","$c"]}}}).result[0].total;
print("a + b + c = " + total2);
if (!(total2 == 5)) {
print("ERROR: a + b + c should be 5")
}
}
test_add();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment