Nested push in Mongoose I have a user schema like that:
name: String,
nick: String,
email: String,
password: String,

bio: String,
color: String,
followers: [String],
followings: [String],

posts: [{
    author: {
        name: String,
        nick: String
    },
    content: String,
    date: Date,
    simpleDate: String,
    color: String,
    likes: [String]
}]

I want to when user push the like button my backend take the id of post and add user's nick to array that named &quot;likes&quot;. So I want to find the object that has post that has this id and add a new string to likes array of it.
User.findOneAndUpdate({'posts._id': req.params.postId},{$push:{posts:{likes:{likes:req.header.authenticatedUser.nick}}}},
    (err,result) =&gt; {...});

I tried something like that but it's not working and looks like very wrong.
How can I find and push to nested object like that?
-edit-
When I use the code below
User.findOneAndUpdate({'posts._id': req.params.postId},{&quot;$push&quot;:{&quot;posts&quot;:{&quot;likes&quot;:req.header.authenticatedUser.nick}}},(err,results)=&gt;{
    if(err){
        console.log(err);
    }
});

it adds a likes array to posts. But I want add my usurname to likes array of post that has index 2
Before the change your application code, you should try to mongo shell this command on your test environment.
db.test.findOneAndUpdate({},
    {&quot;$push&quot;:
        {&quot;post.2.likes&quot;:&quot;Yunus&quot;}
    })