2013-01-19 60 views
1

夥計蒙古族或蒙古族不支持羣組功能?

在node.js中,不支持mongolian或mongo-native組函數嗎?

蒙戈本地代碼,

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) 

回答

3

如圖the docs看到的,它是由本機驅動程序支持,但是所述group方法採用keyreduce等作爲單獨的參數,而不是場中的對象類的外殼的作用:

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

的在npm中的蒙古包沒有更新,你必須克隆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 
    } 
);