Skip to content
Advertisement

Push object to array in mongodb nodejs [closed]

This is my mongodb collection.

I want to push object to array with findOneAndUpdate().

This is my nodejs code.

JavaScript

How can i do this?

Advertisement

Answer

You can use $push operator for updating an array. Actually you have a few ways too for updating a document like $set operator or find one and change the document then save new document this will be update your document. TLDR code here;

JavaScript

References:

$push

$set

mongoose documents

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement