nested $unwind not working while querying on MongoDB

Anand Saran shared this problem 5 years ago
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.

Replies (2)

photo
1

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.

photo
1

Thanks for opening your issue here! If you're reporting a bug, please make sure you include steps to reproduce it.

  • NoSQLBooster Version
  • Operating System (Windows/Mac/Ubuntu):
  • MongoDB Version
  • Expected Behavior
  • Actual Behavior
  • How to Reproduce (please attach your sample JSON collection)
  • Screenshots

Leave a Comment
 
Attach a file