Mongodb $push进入文档Mongoose中对象中的数组

Mongodb $push进入文档Mongoose中对象中的数组,mongodb,mongoose,mongoose-schema,Mongodb,Mongoose,Mongoose Schema,如何将I$推入mongoose文档中对象中的数组 模式如下所示 { rating: { usersRated: Array, rating: Number } } 我尝试了{rating:{$push:{usersrrated:data.userId}}},但它不起作用。你应该这样做 就你而言: model.update({ _id: id }, { $push: { 'rating.usersRated': data.userId }}, callback);

如何将I$推入mongoose文档中对象中的数组

模式如下所示

{
  rating: {
      usersRated: Array,
      rating: Number
  }
}
我尝试了
{rating:{$push:{usersrrated:data.userId}}}
,但它不起作用。

你应该这样做

就你而言:

model.update({ _id: id }, { $push: { 'rating.usersRated': data.userId }}, callback);
更新时,您应该通过