Skip to content

Instantly share code, notes, and snippets.

@seka
Last active August 29, 2015 14:16
Show Gist options
  • Save seka/a2259d768dca21d3c5fb to your computer and use it in GitHub Desktop.
Save seka/a2259d768dca21d3c5fb to your computer and use it in GitHub Desktop.
node.jsでmongooseを使っている際、純粋なgroup メソッドを利用する。
var mongoose = require("mongoose");
var DBName = "";
M.prototype.connection = mongoose.createConnection("mongodb://127.0.0.1/" + DBName, callback);
var database = M.connection.db
var collection = database.collection("datas");
// keys (object), condition (object), initial (object), reduce (function), finalize (function), [options] (object), callback
collection.group({"id":true}, null, {}, function (curr, result) {
result._id = curr._id;
}, function(err, results){
if (err){
console.log(err);
throw err;
}
console.log(results);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment