Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #98 from sevifives/448e41deb6c790fb299546221e0c91b…

…e39a463c1

Add group and tests for group
  • Loading branch information...
commit f1a6bdc547db1021321acc869d530ac05dda24d3 2 parents c41c213 + 448e41d
@marcello3d authored
Showing with 24 additions and 1 deletion.
  1. +1 −1  Readme.md
  2. +4 −0 lib/collection.js
  3. +19 −0 test/collection1000.js
View
2  Readme.md
@@ -274,7 +274,7 @@ From http://api.mongodb.org/js/1.8.1/symbols/src/shell_collection.js.html
})</code>
+ <code><strong><em>collection.getDB</em></strong>()</code> get DB object associated with collection implemented as <code><strong>collection.db</strong></code>
+ <code><strong><em>collection.getIndexes</em></strong>()</code> implemented as <code><strong>collection.indexes</strong>(callback)</code>
-+ <code>collection.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )</code>
++ <code><strong>collection.group</strong>( { key : ..., initial: ..., reduce : ...[, cond: ...] } )</code>
+ <code><strong>collection.mapReduce</strong>( mapFunction , reduceFunction , [optional params][, callback])</code>
+ <code><strong>collection.remove</strong>(query[, callback])</code> - see callback note below
+ <code>collection.renameCollection( newName , [dropTarget] )</code> renames the collection.
View
4 lib/collection.js
@@ -275,6 +275,10 @@ MongolianCollection.prototype.findAndModify = function(options, callback) {
}))
}
+MongolianCollection.prototype.group = function (command, callback) {
+ this.db.runCommand({group: command}, callback);
+}
+
MongolianCollection.prototype.distinct = function(key, query, callback) {
if (!callback && typeof query === 'function') {
callback = query
View
19 test/collection1000.js
@@ -52,6 +52,25 @@ module.exports = {
test.done()
})
},
+ "group check": function (test) {
+ collection.group({
+ 'ns': 'test_1000',
+ 'key':'even',
+ 'initial': {evenCount:0, oddCount: 0, total:0},
+ '$reduce': function (doc, out) {
+ ++out[doc.even ? 'evenCount' : 'oddCount'];
+ ++out.total;
+ },
+ finalize: function (out) {}
+ }, function (error,group) {
+ var ret = group.retval[0];
+ test.ifError(error);
+ test.equal(ret.total, 1000);
+ test.equal(ret.evenCount, 500);
+ test.equal(ret.oddCount,500);
+ test.done();
+ });
+ },
"mapped forEach": function(test) {
var counter = 0
collection.find().map(function(item) {
Please sign in to comment.
Something went wrong with that request. Please try again.