I have this schema to represent a user:
const UserSchema = mongoose.Schema({
username: {
type: String,
required: false
},
social: [{
facebook: {
type: String,
required: false
},
twitter: {
type: String,
required: false
}
}]
});
how can I save values using this schema? What I am doing so far:
user.username = username;
user.social['facebook'] = facebook;
user.social['twitter'] = twitter;
await user.save();
this works for username but social is still an empty array. I also tried
user.social.facebook = facebook;
user.social.twitter = twitter;
same result:
"social" : [ ]