diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-09-09 21:38:55 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-09-09 21:38:55 -0400 |
commit | 30d4cf6114b4eb8321b67baabf52a592d0d80014 (patch) | |
tree | b06f165096a2c1f24fadd0bdfd00426566d704d1 | |
parent | 780d6dfe1106952278032e01c209e93b365afdd3 (diff) | |
download | mongo-30d4cf6114b4eb8321b67baabf52a592d0d80014.tar.gz |
just an example of group sum
-rw-r--r-- | jstests/group1.js | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/jstests/group1.js b/jstests/group1.js index 3f574461028..df747471881 100644 --- a/jstests/group1.js +++ b/jstests/group1.js @@ -26,6 +26,10 @@ ret = t.groupcmd( { key : {} , reduce : p.reduce , initial : p.initial } ); assert.eq( 1 , ret.length , "ZZ 2" ); assert.eq( 5 , ret[0].count , "ZZ 3" ); +ret = t.groupcmd( { key : {} , reduce : function(obj,prev){ prev.sum += obj.n } , initial : { sum : 0 } } ); +assert.eq( 1 , ret.length , "ZZ 4" ); +assert.eq( 15 , ret[0].sum , "ZZ 5" ); + t.drop(); t.save( { "a" : 2 } ); |