不支持 mongolian 或 mongo-native 组功能? [英] mongolian or mongo-native is not supported group function?

查看:27
本文介绍了不支持 mongolian 或 mongo-native 组功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们

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

In node.js, mongolian or mongo-native is not supported group function?

mongo 原生代码,

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)

<小时>

和蒙古代码,


and mongolign code,

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方法需要keyreduce等作为单独的参数而不是像 shell 那样的对象中的字段:

As seen in the docs, it's supported by the native driver, but the group method takes key, reduce, etc. as separate parameters instead of fields in an object like the shell does:

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

这篇关于不支持 mongolian 或 mongo-native 组功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆