【发布时间】:2015-09-18 06:50:51
【问题描述】:
我在我的项目中使用猫鼬。当我的集合中的文档数量变大时,find+sort 的方法会变慢。所以我改用 aggregate+$sort 。我只是想知道为什么?
【问题讨论】:
-
find将在内部进行迭代,然后sort因此,它需要更多的时间然后aggregate+sort。
标签: mongodb mongoose aggregation-framework
我在我的项目中使用猫鼬。当我的集合中的文档数量变大时,find+sort 的方法会变慢。所以我改用 aggregate+$sort 。我只是想知道为什么?
【问题讨论】:
find 将在内部进行迭代,然后 sort 因此,它需要更多的时间然后 aggregate+sort。
标签: mongodb mongoose aggregation-framework
在没有看到您的数据和查询的情况下,很难回答为什么聚合+排序比查找+排序更快。
但以下是在查找和聚合时适用的内容
查看这个帖子了解更多信息
【讨论】: