Created
February 7, 2017 14:24
-
-
Save flowl/fd647fd9370c51049ae4cc63b7acc1e4 to your computer and use it in GitHub Desktop.
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
db.input.aggregate([ | |
{ | |
$unwind: "$attributes" | |
}, | |
{ | |
$lookup: { | |
from: "input", | |
localField: "attributes.id", | |
foreignField: "attributeId", | |
as: "attribute" | |
} | |
}, | |
{ | |
$addFields: { | |
"attribute.value": "$attributes.value" | |
} | |
}, | |
{ | |
$project: { | |
"attributes": 0 | |
} | |
}, | |
{ | |
$unwind: "$attribute" | |
}, | |
{ | |
$group: { | |
_id: "$_id", | |
type: { | |
"$first": "$type" | |
}, | |
productId: { | |
"$first": "$productId" | |
}, | |
attributes: { | |
"$addToSet": "$attribute" | |
} | |
} | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment