Skip to content

Instantly share code, notes, and snippets.

@fsh905
Created September 22, 2020 02:58
Show Gist options
  • Save fsh905/d5fd3d60688d05887316ae25322f50f5 to your computer and use it in GitHub Desktop.
Save fsh905/d5fd3d60688d05887316ae25322f50f5 to your computer and use it in GitHub Desktop.
product query
db.getCollection('product').aggregate([
{$match: {"productItems.id": 23456}},
{$unwind: "$productItems"},
{$match: {"productItems.id": 23456}},
{
$lookup:
{
from: "options",
localField: "productItems.id",
foreignField: "pid",
as: "options"
}
},
{$unwind: "$options"},
{
$project: {
"is_variants": "$productItems.is_variants",
"totalVariants": "$productItems.totalVariants",
"id": "$productItems.id",
"tetle": "$productItems.tetle",
"options": 1
}
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment