mongoose 更新元素 DeprecationWarning: collection.update is deprecated. Use updateOne, updateMany

版权声明:转载请评论留言 https://blog.csdn.net/solocao/article/details/85003912

我一开始的写法:

const updOne = await this.update({ _id: verify_id }, {
  $set: {
    // 认证通过,状态设置为1
    state: 1,
    // 审核操作人
    verify_user,
    verify_at: Date.now()
  }
});

使用mongoose更新元素值,报错了DeprecationWarning: collection.update is deprecated. Use updateOne, updateMany
去官网查看原因:https://mongoosejs.com/docs/deprecations.html
在这里插入图片描述
原因是使用mongoose需要遵循它的新语法,改造成如下写法:

const updOne = await this.update({ _id: verify_id }, {
 // 认证通过,状态设置为1
  state: 1,
  // 审核操作人
  verify_user,
  verify_at: Date.now()
});

解决报错。

猜你喜欢

转载自blog.csdn.net/solocao/article/details/85003912
今日推荐