【发布时间】:2016-05-24 18:16:57
【问题描述】:
我正在尝试通过 Mongoose 更新我的 MongoDB 中的文档,但由于某种原因无法找到请求的文档...
Call.update({_id: data.call._id}, { $set: { approved: value }}, function (error, response) {
console.log(error);
console.log(response);
if (error) {
callback(error, null);
} else {
callback(null, response);
}
});
data.call._id 包含一个有效的文档_id 并且approved 的类型是Number。
response 输出以下内容:
{ ok: 1, nModified: 0, n: 0, lastOp: { _bsontype: 'Timestamp', low_: 0, high_: 0 }, electionId: 56a92375bfb5c1abc4e825a7 }
数据库中的文档永远不会更新...value 将被设置为 1 或 -1,具体取决于之前的条件。
型号:
const callSchema = new Schema({
start: Date,
duration: String,
callerNumber: String,
callerNumberAreaCode: String,
trackingNumber: String,
destinationNumber: String,
answered: String,
customerId: String,
approved: Number
}, { collection: 'calls'});
const Call = mongoose.model('Call', callSchema);
【问题讨论】: