【发布时间】:2015-04-24 05:14:20
【问题描述】:
我从 Mongoose idGetter 函数中收到以下错误。谁能解释一下可能是什么原因造成的?
return this.$__._id = null == this._id
^
TypeError: Cannot set property '_id' of null
at model.idGetter (e:\Users\Christine\test\mvt\node_modules\mongoose\lib\schema.js:98:23)
错误情况涉及多个客户端请求执行文档删除(在同一集合中的不同文档上),在通过 Internet 访问的数据库上(即响应时间慢)。访问已删除文档之一的 id 时发生故障。似乎有一个小的计时窗口发生 - 我尝试调试它的所有内容都会导致问题“消失”。
应用代码概要:
Details.findOneAndRemove({ _id : remove_id}, afterRemove);
function afterRemove(err, removedDoc){
if (!err && removedDoc){
OtherDetails.find({ _id: some_id}, afterFind);
}
function afterFind(err, foundDoc){
if (!err && foundDoc){
// next line causes exception
if (foundDoc.details_id === removedDoc.id) { // do stuff };
}
}
}
【问题讨论】: