Answer the question
In order to leave comments, you need to log in
How to change the property of the model you refer to?
Hello. I am writing an application that has workouts consisting of exercises. I create models like this:
const valuesOfExercise = new Schema({
exercise: {type: Schema.Types.ObjectId, ref: "Exercise"},
repeats: {type: Number, required: true},
measure: {type: Number, required: true},
order: {type: Number}
})
const workoutSchema = new Schema({
user: { type: Schema.Types.ObjectId, ref: "User" },
date: {type: Date},
exercises: [valuesOfExercise]
})
const {itemToDelete} = req.body
Workout.find({user: req.payload._id}).populate({path: 'exercises.exercise'})
.exec((err, item)=>{
item.map((ex, i)=>{
let arr = [...ex.exercises]
arr.splice(itemToDelete.order, 1)
arr.map((ex, index)=>{
ex.order = index;
})
console.log(arr)
})
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question