相关疑难解决方法(0)

Mongodb数组$ push和$ pull

我想从数组中提取一些值并同时尝试更新它.

    userSchema.statics.experience = function (id,xper,delet,callback) {
    var update = {
      $pull:{
        'profile.experience' : delet
      },

        $push: {
          'profile.experience': xper
        }
  };
  this.findByIdAndUpdate(id,update,{ 'new': true},function(err,doc) {
    if (err) {
      callback(err);
    } else if(doc){
      callback(null,doc);
    }
  });
};
Run Code Online (Sandbox Code Playgroud)

我得到的错误就像 MongoError: exception: Cannot update 'profile.experience' and 'profile.experience' at the same time

mongodb

16
推荐指数
2
解决办法
9912
查看次数

标签 统计

mongodb ×1