I am new to Mongoose and MongoDB, and I'm trying to update the values of the following model :
var userSchema = mongoose.Schema({
username : String,
playlist : [{
name : String,
active : {type: Boolean, default: false},
}]
});
What I want to do is to set all the playlists of one user to false, then set only one to true. And by doing the following request, it happens to erase the informations in my playlists :
this.model('User').findByIdAndUpdate(userId, {$set:{playlist:{active:false}}})
.exec(
function(err, user){
//DO callback treatment here
});
I have seen some people saying that once they retrieved the User, they had to do a foreach on the subarray, but is there no way to use directly mongoose and mongodb to do such a treatment ?
Thanks for your answer !