I'm relatively new to Node.js and Mongo/Mongoose, and I'm having a very difficult time troubleshooting a specific Mongoose error:
VersionError: No matching document found.
(Entire error trace/stack at the bottom of this question.)
This blog post pretty clearly outline how a VersionError might occur:
(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 VersionError
.)
Core Question: Is there some way to display the offending save()
operation? Or which document failed to save? Or anything at all?! ;)
The Challenge: this is a relatively large code base with many arrays, and I am unsure how to begin to troubleshoot the problem. In particular, the error trace/stack does NOT seem to show where the problem exists. See below:
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)