I have a user schema with an array of task ObjectId's and I'm trying to figure out how I can go about removing them.
User Schema
const UserSchema = new Schema({
email: {
type: String,
lowercase: true,
index: { unique: true }
},
password: {
type: String,
},
tasks: [{
type: Schema.Types.ObjectId,
ref: 'task'
}]
})
Below is the code I've tried to use but I'm not sure where to go from with what I've done so far.
router.delete('/deleteUsersTasks/:_id', async(req, res, next) => {
User.findById({_id: req.params._id}, (err, user) => {
User.findByIdAndRemove(tasks: req.body._id)
});
Is there a better way to remove the task ObjectId from the tasks array in the user schema or am I just missing something in my route currently?