Created
December 16, 2017 01:51
-
-
Save Signorini/4c49a05fb1461d7626ecf83a52294183 to your computer and use it in GitHub Desktop.
Join mongo db - with lookup
This file contains hidden or 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
db.applications.aggregate([ | |
{ "$unwind": "$servers" }, | |
{ "$lookup": { | |
"from": "servers", | |
"localField": "servers", | |
"foreignField": "_id", | |
"as": "servers_details" | |
}}, | |
// Unwind the result arrays ( likely one or none ) | |
{ "$unwind": "$servers_details" }, | |
// Group back to arrays | |
{ "$group": { | |
"_id": "$_id", | |
"servers": { "$push": "$servers" }, | |
"servers_details": { "$push": "$servers_details" } | |
}} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment