nested $unwind not working while querying on MongoDB
Cannot Reproduce
Hi,
I have been trying to use the following query to unwind an array inside of an array to group certain attributes, the 2nd $unwind is not working.
The query is below:
db.ExecutionPlan.aggregate([
{$unwind: "$nodes"},
{$unwind: "$noses.mileStones"},
{$group:{_id:
{ "node_type":"$nodes.type",
"node_sequence":"$nodes.sequence",
"mileStone_seq":"$nodes.mileStones.sequence",
"mileStone_type" : "$nodes.mileStones.typeOfMileStone",
"mileStone_eventType" : "$nodes.mileStones.eventType"
}
}
}
]).
Can you suggest if there is an issue in the query or if MongoDb does not support nested unwinds. Thanks.
Also tried the following:
db.ExecutionPlan.aggregate([
{$unwind: "$nodes"},
//{$unwind: "$noses.mileStones"},
{$group:{_id:
{ "houseBill":"$houseBill",
"containerNo":"$containerNo",
"node_type":"$nodes.type",
"node_sequence":"$nodes.sequence",
"mileStones":"$nodes.mileStones"
}
}
},{
$unwind: "$mileStones"
}
,{
$group:{_id:
{ "houseBill":"$houseBill",
"containerNo":"$containerNo",
"node_type":"$node_type",
"node_sequence":"$node_sequence",
"mileStone_seq":"$mileStones.sequence",
"mileStone_type":"$mileStones.typeOfMileStone",
"mileStone_eventType":"$mileStones.eventType"
}
}
}
])
Still not working.
Also tried the following:
db.ExecutionPlan.aggregate([
{$unwind: "$nodes"},
//{$unwind: "$noses.mileStones"},
{$group:{_id:
{ "houseBill":"$houseBill",
"containerNo":"$containerNo",
"node_type":"$nodes.type",
"node_sequence":"$nodes.sequence",
"mileStones":"$nodes.mileStones"
}
}
},{
$unwind: "$mileStones"
}
,{
$group:{_id:
{ "houseBill":"$houseBill",
"containerNo":"$containerNo",
"node_type":"$node_type",
"node_sequence":"$node_sequence",
"mileStone_seq":"$mileStones.sequence",
"mileStone_type":"$mileStones.typeOfMileStone",
"mileStone_eventType":"$mileStones.eventType"
}
}
}
])
Still not working.
Thanks for opening your issue here! If you're reporting a bug, please make sure you include steps to reproduce it.
Thanks for opening your issue here! If you're reporting a bug, please make sure you include steps to reproduce it.
Replies have been locked on this page!