mongoose findOneAndUpdate 查找更新后的数据{ new: true }

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

需要增加一个配置项 { new: true },则可以查找后面的内容。

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

需要查询具体哪些字段

User.findOneAndUpdate(
  { "_id": "132324" },
  { "$set": { "hair_color": "yellow" } },
  {
   "fields": { "first_name":1, "last_name": 1 },
   "new": true 
  }
).exec(...)

猜你喜欢

转载自blog.csdn.net/solocao/article/details/86489331