How Can I Make Nested $Project Make Work Without Using Foreach : Only Using Aggregate
db.college.insert([{
code: "xyz",
tags: [ "school", "book", "bag", "headphone", "appliance" ],
qty: [
{ size: "S", num: 10, color: "blue" , items : {a : 11 , b :23}},
{ size: "M", num: 45, color: "blue" , items : {a : 34 , b :345}},
{ size: "L", num: 100, color: "green" , items : {a : 45 , b :4545}}
]
},
{
code: "abc",
tags: [ "appliance", "school", "book" ],
qty: [
{ size: "6", num: 100, color: "green", items : {a : 341 , b :656} },
{ size: "6", num: 50, color: "blue" , items : {a : 45 , b :45}},
{ size: "8", num: 100, color: "brown" , items : {a : 451 , b :45}}
]
},
{
code: "efg",
tags: [ "school", "book" ],
qty: [
{ size: "S", num: 10, color: "blue" , items : {a : 34 , b :55}},
{ size: "M", num: 100, color: "blue" , items : {a : 545 , b :65}},
{ size: "L", num: 100, color: "green" , items : {a : 454 , b :45}}
]
},
{
code: "ijk",
tags: [ "electronics", "school" ],
qty: [
{ size: "M", num: 100, color: "green" , items : {a : 1 , b :2}}
]
}])
SCENARIO IS LIKE :
IF LEVEL == 1 Then Bring "Only" Quantity And "Not" Nested Items In Quantity :
HERE SINGLE $project Is WORKING :
Query : db.schools3.aggregate(
{
$project : {
id : 1 ,
qty : 1
}
}).result
IF LEVEL == 2 :Then Bring Quantity And Also Items Inside Quantity :
HERE NESTED $project NOT WORKING :
Query : db.schools3.aggregate(
{
$project : {
id : 1 ,
qty : {$project :
{items : 1}
}
}
}).result
How Can I Make Nested $Project Make Work Without USing Foreach : Only Using Aggregate