Skip to content
Advertisement

Mongoose update Sub-Document

How to updating sub-document in mongoose:

this is my JSON DATA

JavaScript

This is the post Schema.

JavaScript

this is the NodeJs part

JavaScript

**

I got this response in Postman: post.comments.update is not a function it accept post.update but it’s not what i want because the property message is in the sub-doc of each post object, any help Please


**

Advertisement

Answer

You should run the method Model.update() on the Model “Post” not the instace “post” of it. A similar question is answered here.

Advertisement