madushanka mdk
madushanka mdk

Reputation: 163

mongoose push item to array in array of objects

How to push element to marked array?

enter image description here

Upvotes: 1

Views: 329

Answers (1)

Mohammad Yaser Ahmadi
Mohammad Yaser Ahmadi

Reputation: 5051

just try

let commentId = "",
let replies = ""
Model.update(
  { comment: { $elemMatch: { _id: commentId } } },
  {
    $push: { "comment.$.replies": replies  },
  }
);

playground

Upvotes: 2

Related Questions