I'm new with mongo and mongoose and I'd like to know how we can add, delete or edit an object in the database when we have an embedded data model as follow :
var userSchema = mongoose.Schema({
local : {
email : String,
password : String,
},
houses : [
{
phone_numbers : [ {number: String} ],
adresse : String,
}
]
});
module.exports = mongoose.model('User', userSchema);
For example, I would like to add a new "house" to my user.
So I tried :
User.findById(req.user.id, function(err, user){
user.houses.adresse = 'TEST';
user.save();
});
But it does not seem to work and I didn't find how to do that in mongoose docs. Any idea on how I could accomplish that ?
Thanks for your help !