Guys
In node.js, mongolian or mongo-native is not supported group function?
mongo-native code,
var mongodb = require('mongodb');
var Db = mongodb.Db;
var Server = mongodb.Server;
var db = new Db( "test", new Server( "localhost", 27017 ), { w:0 } );
db.collection( "user" ).group( {
key: { },
reduce: function ( curr, result ) { },
initial: { }
} );
result,
/node/ex1/node_modules/mongodb/lib/mongodb/collection.js:1400
if(err != null) return callback(err);
^
TypeError: undefined is not a function
at Collection.group.scope (/node/ex1/node_modules/mongodb/lib/mongodb/collection.js:1400:30)
at Db._executeQueryCommand (/node/ex1/node_modules/mongodb/lib/mongodb/db.js:1812:12)
at Collection.group (/node/ex1/node_modules/mongodb/lib/mongodb/collection.js:1399:13)
at Object.<anonymous> (/node/ex1/repository.js:34:25)
and mongolign code,
var Mongolian = require( "mongolian" );
var server = new Mongolian;
var db = server.db( "test" );
db.collection( "user" ).group( {
key: { },
reduce: function ( curr, result ) { },
initial: { }
} );
result,
db.collection( "user" ).group( {
^
TypeError: Object Mongolian[mongo://localhost:27017]/assistor.user has no method 'group'
at Object.<anonymous> (/node/ex1/repository.js:77:25)
As seen in the docs, it's supported by the native driver, but the group method takes key, reduce, etc. as separate parameters instead of fields in an object like the shell does:
db.collection("user").group(
{},
{},
{ sum: 0 },
function (curr, result) { },
function (err, result) {
// Process the result
}
);
The mongolian package at npm isn't updated, you have to clone the git repository and then link it with npm.
Then the documentation isn't complete, you have to do something like this, it took me a while to make it work.
var Mongolian = require( "mongolian" );
var server = new Mongolian;
var db = server.db( "test" );
db.collection( "user" ).group( {
ns: "user",
key: { },
reduce: function ( curr, result ) { },
initial: { }
},function(error,post){
if(error) console.log(error);
//do something with post.retval
}
);