MongoDB $lookup vs Mongoose populate

≯℡__Kan透↙ 提交于 2020-06-28 05:19:27

问题


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?


回答1:


Thanks to a github thread shared by Grégory NEUT in the question's comments I have been able to establish certain facts:

  1. Mongoose's populate() method does not use MongoDB's $lookup behind the scenes. It simply makes another query to the database.
  2. 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.



来源:https://stackoverflow.com/questions/62557902/mongodb-lookup-vs-mongoose-populate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!