I'm facing an issue while trying to populate the "signedUp" array in my Timetable Schema on MongoDB. Despite successfully updating other fields of the schema, the signedUp array always remains empty. I have verified that the variable being added is not empty.
Below is my Schema:
var TimetableSchema = new mongoose.Schema({
date: {
type: String,
required: true,
trim: true
},
spaces: {
type: Number,
required: true
},
classes: [ClassSchema],
signedUp: [{
type: String
}]
});
Despite multiple attempts, I couldn't add any value to the signedUp array. Here's the excerpt from my API update request:
id = {_id: req.params.id};
space = {spaces: newRemainingCapacity};
signedUp = {$addToSet:{signedUp: currentUser}};
Timetable.update(id, space, signedUp, function(err, timetable){
if(err) throw err;
console.log("updates");
res.send({timetable});
});
Thank you.