MongoDB $lookup 与 Mongoose 填充 [英] MongoDB $lookup vs Mongoose populate
问题描述
我看过这个和其他类似标题的问题,没有回答我的问题.
我正在阅读 mongoose 文档
<块引用>MongoDB 在版本中具有类似连接的 $lookup 聚合运算符 >=3.2.Mongoose 有一个更强大的替代方法,叫做 populate(),它可以让你引用其他集合中的文档.
mongoose 中的 populate()
如何工作,使其比 MongoDB 的 $lookup
更强大?
mongoose 不是一个帮助 nodejs 用户使用 mongodb 的工具.如果是这样,猫鼬如何拥有 MongoDB 没有的功能?像populate()
?
mongoose 的 populate()
方法是否在幕后使用了 MongoDB 的 $lookup
?
感谢 github 线程 由 Grégory NEUT 在问题的评论中分享我已经能够确定某些事实:
- Mongoose 的 populate() 方法在幕后没有使用 MongoDB 的 $lookup.它只是对数据库进行另一个查询.
- Mongoose 没有 MongoDB 没有的功能.
populate()
只是进行两个或多个查询.
<块引用>
mongoose 中的 populate() 如何工作使其比MongoDB 的 $lookup?
在我看来,有些地方可以使用populate()
,有些地方可以使用$lookup
.对于更复杂的查询,聚合管道中的 $lookup
效果最好.
I have seen this and other similar titled questions, none answer my question.
I was going through the mongoose documentation where I read
MongoDB has the join-like $lookup aggregation operator in versions >= 3.2. Mongoose has a more powerful alternative called populate(), which lets you reference documents in other collections.
How does populate()
in mongoose work that makes it more powerful than MongoDB's $lookup
?
Isn't mongoose a tool that helps nodejs users work with mongodb. If so how can mongoose have functionalities that MongoDB does not? Like populate()
?
Does mongoose's populate()
method use MongoDB's $lookup
behind the scenes?
Thanks to a github thread shared by Grégory NEUT in the question's comments I have been able to establish certain facts:
- Mongoose's populate() method does not use MongoDB's $lookup behind the scenes. It simply makes another query to the database.
- Mongoose does not have functionalities that MongoDB does not have.
populate()
just makes two or more queries.
How does populate() in mongoose work that makes it more powerful than MongoDB's $lookup?
In my opinion, there are places to use populate()
and others to use $lookup
. For more complex queries $lookup
in an aggregation pipeline would work best.
这篇关于MongoDB $lookup 与 Mongoose 填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!