title: "VersionError: No matching document found" error on Node.js/Mongoose
body: <p>I'm relatively new to Node.js and Mongo/Mongoose, and I'm having a <em>very</em> difficult time troubleshooting a specific Mongoose error:</p>
  
  <p><strong>VersionError: No matching document found.</strong></p>
  
  <p><em>(Entire error trace/stack at the bottom of this question.)</em></p>
  
  <p>This blog post pretty clearly outline how a VersionError might occur:</p>
  
  <ul>
  <li><a href="http://aaronheckmann.blogspot.com/2012/06/mongoose-v3-part-1-versioning.html" rel="noreferrer">http://aaronheckmann.blogspot.com/2012/06/mongoose-v3-part-1-versioning.html</a></li>
  </ul>
  
  <p><em>(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 <code>VersionError</code>.)</em></p>
  
  <p><strong>Core Question:</strong> Is there some way to display the offending <code>save()</code> operation? Or which document failed to save? Or <em>anything</em> at all?! ;)</p>
  
  <p><strong>The Challenge:</strong> 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:</p>
  
  <pre><code>VersionError: No matching document found.
  at handleSave (&lt;project_path&gt;/node_modules/mongoose/lib/model.js:121:23)
  at exports.tick (&lt;project_path&gt;/node_modules/mongoose/lib/utils.js:408:16)
  at null.&lt;anonymous&gt; (&lt;project_path&gt;/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 (&lt;project_path&gt;/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:391:25)
  at Server.connect.connectionPool.on.server._serverState (&lt;project_path&gt;/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:558:20)
  at MongoReply.parseBody (&lt;project_path&gt;/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:131:5)
  at Server.connect.connectionPool.on.server._serverState (&lt;project_path&gt;/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:517:22)
  at EventEmitter.emit (events.js:96:17)
  </code></pre>