1
votes

How do I $push into the Array which is in the Object in the document in mongoose?

The schema looks like this

{
  rating: {
      usersRated: Array,
      rating: Number
  }
}

I have tried {rating: {$push: {usersRated: data.userId}}}, but it does not work.

1

1 Answers

1
votes

You should update the collection.

In your case:

model.update({ _id: id }, { $push: { 'rating.usersRated': data.userId }}, callback);

On update, you should pass the operator before the fields.