我正在尝试使用 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)