{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3683","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3683/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3683/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3683/events","html_url":"https://github.com/Automattic/mongoose/issues/3683","id":122632405,"number":3683,"title":"Convert populate to use $lookup","user":{"login":"niftylettuce","id":523141,"avatar_url":"https://avatars.githubusercontent.com/u/523141?v=3","gravatar_id":"","url":"https://api.github.com/users/niftylettuce","html_url":"https://github.com/niftylettuce","followers_url":"https://api.github.com/users/niftylettuce/followers","following_url":"https://api.github.com/users/niftylettuce/following{/other_user}","gists_url":"https://api.github.com/users/niftylettuce/gists{/gist_id}","starred_url":"https://api.github.com/users/niftylettuce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niftylettuce/subscriptions","organizations_url":"https://api.github.com/users/niftylettuce/orgs","repos_url":"https://api.github.com/users/niftylettuce/repos","events_url":"https://api.github.com/users/niftylettuce/events{/privacy}","received_events_url":"https://api.github.com/users/niftylettuce/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-17T00:04:16Z","updated_at":"2015-12-17T00:05:25Z","closed_at":null,"body":"Before:\r\n\r\n```js\r\nlib.db.model('Stock').find(stockQuery).populate('product') // ...\r\n```\r\n\r\nAfter:\r\n\r\n```js\r\n            lib.db.model('Stock').collection.aggregate([\r\n              { $match: stockQuery },\r\n              {\r\n                $lookup: {\r\n                  from: 'products',\r\n                  localField: 'product',\r\n                  foreignField: '_id',\r\n                  as: 'product'\r\n                }\r\n              },\r\n              {\r\n                $project: {\r\n                  product: {\r\n                    $arrayElemAt: [ '$product', 0 ]\r\n                  }\r\n                }\r\n              },\r\n              { $sort: sort },\r\n              { $limit: req.query.limit },\r\n              { $skip: req.offset }\r\n            ], callback);\r\n```\r\n\r\nCan we normalize this functionality for population using `aggregate` and `$lookup` into a rewrite of the `populate` function (so it would still function the same, but it'd use `$lookup` instead?"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/165295329","html_url":"https://github.com/Automattic/mongoose/issues/3683#issuecomment-165295329","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/3683","id":165295329,"user":{"login":"niftylettuce","id":523141,"avatar_url":"https://avatars.githubusercontent.com/u/523141?v=3","gravatar_id":"","url":"https://api.github.com/users/niftylettuce","html_url":"https://github.com/niftylettuce","followers_url":"https://api.github.com/users/niftylettuce/followers","following_url":"https://api.github.com/users/niftylettuce/following{/other_user}","gists_url":"https://api.github.com/users/niftylettuce/gists{/gist_id}","starred_url":"https://api.github.com/users/niftylettuce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niftylettuce/subscriptions","organizations_url":"https://api.github.com/users/niftylettuce/orgs","repos_url":"https://api.github.com/users/niftylettuce/repos","events_url":"https://api.github.com/users/niftylettuce/events{/privacy}","received_events_url":"https://api.github.com/users/niftylettuce/received_events","type":"User","site_admin":false},"created_at":"2015-12-17T00:05:25Z","updated_at":"2015-12-17T00:05:25Z","body":"Note that $lookup is only available in MongoDB 3.2"}}