How to add values to an array in MongoDB

I have this structure:
The code I wrote only updates the existing object inside the array, how can I add more object each time instead of updating the single one?

My code:

app.patch("/newpost", async(req,res)=>{
    const token = jwt.verify(req.body.token,process.env.SECRET)
    const addedPost =  await NewUser.updateOne(
        {_id:token._id},{$set:{posts: {content:req.body.content}}}

{ _id: 1 },
{ $push: { arrayName: 89 } }

Here, for more information, read the document about $push in mongodb docs.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.