0

In Mongoose, I am able to extract data that references another Collection.

For instance, I can do

Comment.find().populate('user').then(comment => {
  //
})

such that comment has all its normal fields (text, createdAt, etc.), but it is also populated with all the fields from user, such that it now has comment.user.username, comment.user.full_name, etc.

How can I obtain the same with PyMongo?

Jamgreen
  • 10,329
  • 29
  • 113
  • 224
  • Why? `.populate()` is kind of an old concept that is basically superseded by [`$lookup`](https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/) in modern MongoDB releases. All `.populate()` actually does is issue another query and merges the results with the previous query. `$lookup` is a lot more effective as it happens on the "server" as opposed to pulling all results over the network to the "client". – Neil Lunn Aug 17 '17 at 10:13
  • Oh didn't knew. How can I use `$lookup` with pymongo? – Jamgreen Aug 17 '17 at 10:13
  • Same way you use it with any language. All query and aggregation DSL does not change, no matter which language is used. – Neil Lunn Aug 17 '17 at 10:14

0 Answers0