小编Der*_*Kim的帖子

是什么导致 Mongoose updateMany 返回 {acknowledged: false }`

我正在尝试使用 MongoDB 为 Express 应用程序设置通知。

我有一个 API 端点,我将$push用户的 id 添加到readByMongoDB 中的字段,以在检索用户的通知后将其“标记”为已读。当我向此端点发出请求时,它会返回200其通知,但不会对 MongoDB 中的通知文档进行任何更新。console.log在回调中查询响应给了我{ acknowledged: false }。根据Mongoose 文档acknowledged是 a Boolean indicating everything went smoothly,但是有关acknowledged查询/写入过程中是什么以及在哪一点导致它发生的信息很少。由于它没有返回任何错误,我找不到解决问题的方法。

有人能够阐明它到底acknowledged: false是什么以及通常导致它的原因,以及为什么它不会抛出错误。

模型:

const notificationSchema = new Schema({
  timestamp: {
    type: Date,
    required: true
  },
  type: {
    type: String,
    required: true,
    enum: [
      'newCustomer',
      'contractSigned',
      'invoicePaid',
      'warrantyExp',
      'assignedProject'
    ]
  },
  recipients: [{
    type: Schema.Types.ObjectId,
    ref: 'Employee',
    required: true, …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js express

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

express ×1

mongodb ×1

mongoose ×1

node.js ×1