Created
May 16, 2020 18:43
-
-
Save hubgit/5293aab3eb4a086e5a0ea10d6a9be261 to your computer and use it in GitHub Desktop.
MongoDB aggregate query with lookup and unwind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const items = await Item.aggregate([ | |
{ | |
$project: { | |
body: 0, | |
}, | |
}, | |
{ | |
$lookup: { | |
from: 'users', | |
localField: 'uid', | |
foreignField: '_id', | |
as: 'user', | |
}, | |
}, | |
{ $unwind: '$user' }, | |
]).toArray() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment