Populate document with other fields

Multi tool use


Populate document with other fields
I got the following document:
{
"_id": "5b5df332879b4769739e3ed0",
"name": "Back workout",
"exercises": [{
"_id": "5b5df9a7879b4769739e3ed1",
"results": [{"reps":"10","weight":"85"}, {"reps":"8","weight":"70"}]
}]
}
I want to populate the exercise based on the _id
and also append the results
data.
_id
results
Expected output:
{
"_id": "5b5df332879b4769739e3ed0",
"name": "Back workout",
"exercises": [{
"_id": "5b5df9a7879b4769739e3ed1",
"name": "EXERCISE_NAME",
"results": [{"reps":"10","weight":"85"}, {"reps":"8","weight":"70"}]
}]
}
My Schema looks like this:
const WorkoutSchema = new Schema({
_id: Schema.Types.ObjectId,
name: String,
exercises: [{
_id: { type: Schema.Types.ObjectId, ref: 'Exercise' },
results: Array,
}],
createdAt: Date,
updatedAt: Date,
});
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.