各位
在node.js中,蒙古语或mongo-native不支持组功能?
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)
最佳答案
如the docs中所示,它受 native 驱动程序支持,但 group
方法将 key
、reduce
等作为单独的参数,而不是对象中的字段,例如shell 的作用是:
db.collection("user").group(
{},
{},
{ sum: 0 },
function (curr, result) { },
function (err, result) {
// Process the result
}
);
关于node.js - 蒙古语或蒙古语 native 不支持群组功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14415262/