Populate document with other fields

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Blogger: Contempo template have managed to get the posts to post in full but there is still a “snippet” of the post at the bottom of each full post