我对Node比较陌生.js和Mongo/Mongoose,我在排除特定Mongoose错误时遇到了very个困难:
VersionError: No matching document found.
(Entire error trace/stack at the bottom of this question.)
这篇博客文章非常清楚地概述了VersionError是如何发生的:
(TL;DR - "Mongoose v3 now adds a schema-configurable version key to each document. This value is atomically incremented whenever a modification to an array potentially changes any array’s elements position." If you try to save a document, but the version key no longer matches the object you have retrieved, you get the above 100.)
Core Question:.有没有什么方法可以显示违规的save()
操作?或者哪个文档未能保存?或者是anything个?!;)
The Challenge:这是一个包含许多数组的相对较大的代码库,我不确定如何开始解决该问题.特别是,错误跟踪/堆栈似乎没有显示问题所在.见下文:
VersionError: No matching document found.
at handleSave (<project_path>/node_modules/mongoose/lib/model.js:121:23)
at exports.tick (<project_path>/node_modules/mongoose/lib/utils.js:408:16)
at null.<anonymous> (<project_path>/node_modules/mongoose/node_modules/mongodb/lib/mongodb/collection.js:484:9)
at g (events.js:192:14)
at EventEmitter.emit (events.js:126:20)
at Server.Base._callHandler (<project_path>/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:391:25)
at Server.connect.connectionPool.on.server._serverState (<project_path>/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:558:20)
at MongoReply.parseBody (<project_path>/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:131:5)
at Server.connect.connectionPool.on.server._serverState (<project_path>/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:517:22)
at EventEmitter.emit (events.js:96:17)