I have following collection
[
{
"receiverWorkout": {
"_id": "5b4f3920c805e1299b90716c",
"name": "nmbnmbnmnbm",
"exercises": [
{
"_id": "5b4f3920c805e1299b90716f",
"reps": 0,
"weights": 0
},
{
"_id": "5b4c3920c805e1299b90716f",
"reps": 4,
"weights": 0
}
]
},
"senderWorkout": {
"_id": "5b4f11f16cf99524f21d2287",
"name": "nmbnmbnmnbm",
"exercises": [
{
"_id": "5b4f11f16cf99524f21d2288",
"reps": 12,
"weights": 0
},
{
"_id": "5b4f7920c805e1299b90716f",
"reps": 8,
"weights": 0
}
]
}
}
]
I need to compare both the exercises array and add new field called won to only senderWorkout ... Winning will be calculated on the reps field... And same index exercises will be matched i.e. first with first exercise and second with second exercise...
So my expected output will be
[
{
"receiverWorkout": {
"_id": "5b4f3920c805e1299b90716c",
"name": "nmbnmbnmnbm",
"exercises": [
{
"_id": "5b4f3920c805e1299b90716f",
"reps": 0,
"weights": 0
},
{
"_id": "5b4c3920c805e1299b90716f",
"reps": 4,
"weights": 0
}
]
},
"senderWorkout": {
"_id": "5b4f11f16cf99524f21d2287",
"name": "nmbnmbnmnbm",
"exercises": [
{
"_id": "5b4f11f16cf99524f21d2288",
"reps": 12,
"weights": 0,
"result": "won"
},
{
"_id": "5b4f7920c805e1299b90716f",
"reps": 2,
"weights": 0,
"result": "lost"
}
]
}
}
]