I have a document called MentorProfile
that has a reference to document CommentFeed
. I am executing the following:
MentorProfile.findOneAndUpdate(
{
_id: req.body.profileId,
'lessons._id': req.body.lessonId,
'lessons.completedList.userData': { $ne: req.user._id }
},
{
$push: {
'lessons.$.completedList': {
name: req.user.name,
avatar: req.body.userAvatar,
userRecord: req.user._id
}
},
$push: {
'lessons.$.commentFeed.comments': {
user:{name:'name', avatar:'avatar', userRecord:'8u38u3jfj'}
text: 'test'
}
}
},
{ new: true }
)
I am wanting to push a new comment to the comments array, where the array is nested as follows:
MentorProfile>CommentFeed>comments
The code snippet I attached doesn't work, i'm sure i'm missing something obvious
MentorProfile
snippet of relevant info
lessons: [
{
completedList: [
{
name: { type: String, required: true },
avatar: { type: String, required: true },
userData: {
type: Schema.Types.ObjectId,
ref: 'User'
}
}
],
stepType: { type: String, required: true },
commentFeed: { type: Schema.Types.ObjectId, ref: 'CommentFeed', required: true }
}
]
CommentFeed
snippet
comments: [
{
user: {
name: { type: String, required: true },
avatar: { type: String, required: true },
userRecord: {
type: Schema.Types.ObjectId,
ref: 'User'
}
},
text: { type: String, required: true }]}