Browse Source

Implement group

saintedlama/travis-non-legacy
saintedlama 9 years ago
parent
commit
31d98d2c89
  1. 21
      lib/collection.js

21
lib/collection.js

@ -224,27 +224,10 @@ Collection.prototype.isCapped = function (cb) {
}
Collection.prototype.group = function (doc, cb) {
var cmd = {
group: {
ns: this._name,
key: doc.key,
initial: doc.initial,
$reduce: new Code(doc.reduce.toString()),
out: 'inline',
cond: doc.cond
}
}
if (doc.finalize) cmd.group.finalize = new Code(doc.finalize.toString())
if (doc.keys) cmd.group.$keyf = new Code(doc.keys.toString())
var self = this
this._getConnection(function (err, server) {
this._getConnection(function (err, connection) {
if (err) return cb(err)
server.command(self._dbname + '.$cmd', cmd, function (err, result) {
if (err) return cb(err)
cb(null, result.result.retval)
})
connection.collection(self._fullColName()).group(doc.key || doc.keyf, doc.cond, doc.initial, doc.reduce, doc.finalize, cb)
})
}

Loading…
Cancel
Save