node.js - 蒙古语或蒙古语 native 不支持群组功能?

标签 node.js mongodb

各位

在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 方法将 keyreduce 等作为单独的参数,而不是对象中的字段,例如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/

相关文章:

php - CakePHP 2 找不到插件

javascript - 在 getStaticProps 函数中序列化 Next.js 时出错?

javascript - Mongoose 自定义验证在 Controller 中不起作用

node.js - Node js在转换为json之前合并xlsx列

node.js - Postgres 服务器没有响应 nodejs 请求

javascript - 从 JSON Node js 读取键值

javascript - 编辑嵌入在 Discord Music Bot 中的 'Now Playing'

javascript - 使用 waitForSelector 方法在 Puppeteer JS 中更改类名时获取元素

mongodb - 如何在mongoDB与python集成中编写原子操作

MongoDB 对所有文档进行计数和分组