Last active
August 29, 2015 14:16
-
-
Save seka/a2259d768dca21d3c5fb to your computer and use it in GitHub Desktop.
node.jsでmongooseを使っている際、純粋なgroup メソッドを利用する。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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