mongolian或mongo-native不支持组功能?

时间:2013-01-19 14:17:24

标签: node.js mongodb

专家

在node.js中,mongolian或mongo-native不支持组功能吗?

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: { }
} );

结果,

/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)

和mongolign代码,

var Mongolian   = require( "mongolian" );
var server  = new Mongolian;
var db      = server.db( "test" );

db.collection( "user" ).group( {
    key: { },
    reduce: function ( curr, result ) { },
    initial: { }
} );

结果,

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)

2 个答案:

答案 0 :(得分:3)

the docs所示,本机驱动程序支持它,但group方法将keyreduce等作为单独的参数而不是字段中的字段像shell这样的对象:

db.collection("user").group(
    {},
    {},
    { sum: 0 },
    function (curr, result) { },
    function (err, result) {
        // Process the result
    }
);

答案 1 :(得分:0)

npm的mongolian包没有更新,你必须克隆git存储库然后用npm链接它。

然后文档不完整,你必须做这样的事情,我需要一段时间才能使它工作。

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
   }
);