蒙古族或蒙古族不支持群组function?
伙计们
在node.js中,蒙古语或mongo-native不支持组function?
mongo本地代码,
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)
和蒙古国的代码,
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)
正如在文档中看到的 ,它受本地驱动程序的支持,但是group
方法将key
, reduce
等作为单独的参数,而不是像shell那样的对象中的字段:
db.collection("user").group( {}, {}, { sum: 0 }, function (curr, result) { }, function (err, result) { // Process the result } );
在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 } );