summaryrefslogtreecommitdiff
path: root/jstests/core/group6.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/group6.js')
-rw-r--r--jstests/core/group6.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/jstests/core/group6.js b/jstests/core/group6.js
new file mode 100644
index 00000000000..b77a37a5d11
--- /dev/null
+++ b/jstests/core/group6.js
@@ -0,0 +1,32 @@
+t = db.jstests_group6;
+t.drop();
+
+for( i = 1; i <= 10; ++i ) {
+ t.save( {i:new NumberLong( i ),y:1} );
+}
+
+assert.eq.automsg( "55", "t.group( {key:'y', reduce:function(doc,out){ out.i += doc.i; }, initial:{i:0} } )[ 0 ].i" );
+
+t.drop();
+for( i = 1; i <= 10; ++i ) {
+ if ( i % 2 == 0 ) {
+ t.save( {i:new NumberLong( i ),y:1} );
+ } else {
+ t.save( {i:i,y:1} );
+ }
+}
+
+assert.eq.automsg( "55", "t.group( {key:'y', reduce:function(doc,out){ out.i += doc.i; }, initial:{i:0} } )[ 0 ].i" );
+
+t.drop();
+for( i = 1; i <= 10; ++i ) {
+ if ( i % 2 == 1 ) {
+ t.save( {i:new NumberLong( i ),y:1} );
+ } else {
+ t.save( {i:i,y:1} );
+ }
+}
+
+assert.eq.automsg( "55", "t.group( {key:'y', reduce:function(doc,out){ out.i += doc.i; }, initial:{i:0} } )[ 0 ].i" );
+
+assert.eq.automsg( "NumberLong(10)", "t.group( {$reduce: function(doc, prev) { prev.count += 1; }, initial: {count: new NumberLong(0) }} )[ 0 ].count" ); \ No newline at end of file