Skip to content

Instantly share code, notes, and snippets.

@seka
Last active Aug 29, 2015
Embed
What would you like to do?
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