聚合函数内部使用的 $match
操作符和 Mongodb 中的常规 find
有什么区别?
为什么 find
函数不允许像聚合函数那样重命名字段名称?
例如总的来说,我们可以传递以下字符串:
{ "$project" : { "OrderNumber" : "$PurchaseOrder.OrderNumber" , "ShipDate" : "$PurchaseOrder.ShipDate"}}
而 find 不允许这样做。
为什么聚合输出不作为 DBCursor 或 List 返回?还有为什么我们不能统计返回的文件?
谢谢。
最佳答案
Why does not the aggregate output return as a DBCursor or a List?
创建聚合框架是为了解决需要 map-reduce 的简单问题。
此框架通常用于计算需要完整 db 作为输入和少量文档作为输出的数据。
What is the difference between the $match operator used inside the aggregate function and the regular find in Mongodb?
正如您所说,其中一个区别是返回类型。查找操作输出返回为 DBCursor。
其他区别:
and also why can't we get a count of the documents that are returned?
你可以。只需计算结果数组中的元素数量或将以下命令添加到管道末尾:
{$group: {_id: null, count: {$sum: 1}}}
Why doesn't the find function allow renaming the field names like the aggregate function?
MongoDB 很年轻,功能还在不断涌现。也许在未来的版本中,我们将能够做到这一点。重命名字段在 aggregation 中比在 find 中更重要。
MongoDB 2.6 aggregation operations will return a cursor .
MongoDB 2.6 was released with the predicted aggregation changes .
https://stackoverflow.com/questions/16552433/