I couldn't push the data in the nested query
I couldn't understand what I missed in my code (I am new in mongodb just experimenting )
My target is adding 'post' in posts
const Schema = mongoose.Schema;
const UserDetail = new Schema({
username: String,
password: String,
firstname: String,
lastname: String,
email: String,
posts: {
post:{
title: String,
article: String,
comments: {}
}
}
});
const User = mongoose.model('userInfo', UserDetail, 'userInfo');
module.exports = User;
Here my updating code
User.findOneAndUpdate({_id: req.user._id},{ $push: {"posts": { "post" : { "article": req.body.description }} } });
Thank you in advance