Hello everyone, I need some help regarding projection of a particular field inside a deeply nested document.
Consider the following document structure -
"_id": 2020,
"students": {
"1": [{
"_id": {
"$oid": "5f093dc05706776c704f1ce6"
},
"admitted": {
"$date": "2020-07-11T12:42:06.581Z"
},
"type": "management quota",
"paid": 4,
"fOccupation": "Businessman"
},{
"_id": {
"$oid": "5f093dc05706776c704f1ce8"
},
"admitted": {
"$date": "2020-07-11T12:46:06.581Z"
},
"type": "handicapped",
"paid": 0,
"fOccupation": "Beggar"
}],
"2": [{}]
}
Now, I need the data in the following manner:
fOccupation:["Businessman","Beggar"] //An array of all values under object with key = "1"
paid: 0 // Last value of 'paid' in the array under object with key = "1"
I am able to return the fOccupation array just fine but I am not able to project the last value (array.length - 1) of the “paid” property. Please help me out in this regard.