Mongo 3.6的汇总问题 [英] Aggregation issue with Mongo 3.6
问题描述
我正在使用聚合函数,连接3.4 mongodb时没有任何问题.
I was using the aggregate function without any problem connecting a 3.4 mongodb.
当我更改为3.6 db时,
When I change to a 3.6 db,
我已收到消息:除"explain"参数的聚合值外,"cursor"选项是必需的.
对不起,如果它已经发布.我找不到任何解决办法
Sorry if it's already posted. I am unable to find any solutions
推荐答案
在mongo 3.6中,使用聚合时发生了一些变化,必须使用游标,除非您包含了explain选项,否则必须指定游标选项.我遇到了和您一样的错误.现在,您必须像这样
In mongo 3.6 there has been changes while using aggregate you have to use cursor, unless you include the explain option, you must specify the cursor option. I faced same error as you were facing. Now you have to do it like
this.aggregate( [
{ $unwind : "$tags" },
{$group: {_id: '$tags', count: { $sum: 1} }},
{$sort: { count: 1 }}
] ).cursor({}).exec();
现在,您可以使用游标方法cursor.toArray()返回包含游标中所有文档的数组.从聚合返回的游标仅支持对评估的游标(例如cursor.toArray())进行操作的游标方法,要了解更多游标方法,可以单击
Now you can use cursor method cursor.toArray() to return an array that contains all the documents from a cursor. Cursors returned from aggregation only supports cursor methods that operate on evaluated cursors like cursor.toArray(), to know about more cursor methods you can click here and get further.
这篇关于Mongo 3.6的汇总问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!