Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add group and tests for group #98

Merged
merged 1 commit into from

3 participants

@sevifives

Enabling the group option on collections

Signed-off-by: sevifives jdooley@kungfeud.com

@sevifives sevifives Adding group to collections
Enabling the group option on collections
Add a simple test for group

Signed-off-by: sevifives <jdooley@kungfeud.com>
448e41d
@sevifives

Updated the command and added a unit test.

@marcello3d marcello3d merged commit f1a6bdc into marcello3d:master
@Hohenheimsenberg

this change is not available in npm, I had to clone the repo to make it work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 29, 2012
  1. @sevifives

    Adding group to collections

    sevifives authored
    Enabling the group option on collections
    Add a simple test for group
    
    Signed-off-by: sevifives <jdooley@kungfeud.com>
This page is out of date. Refresh to see the latest.
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) {
Something went wrong with that request. Please try again.