title: Node, Mongoose: on save() "VersionError: No matching document found."
body: <p>I'm new to mongoose so this is probably something <em>very</em> simple .. however.</p>
  
  <p>I have a very simple schema that contains a simple array of numbers:</p>
  
  <pre><code>userSchema = new mongoose.Schema({
  name        : String,
  tag_id      : String,
  badges      : [Number]
  });
  
  var user = mongoose.model( 'User', userSchema );
  </code></pre>
  
  <p>Later I want to add a badge to the user. So..</p>
  
  <pre><code>user.findOne({tag_id:tagid}, function(err,doc) {
       if (!doc) callback(false, 'no doc');
  
       // check to see if badge is in array, if not add it
       if ( doc.badges.indexOf(badgeNum) == -1 ) {
           doc.badges.push(badgeNum);
           doc.save( function(err) {
               if (err) callback( false, err );
               else callback( true, '');
           });
       } else {
           callback( false, 'user already had badge' )
       }
   });
  </code></pre>
  
  <p>However whenever I run that code I get a 'VersionError: No matching document found.'</p>
  
  <p>I did a little googling and found reference to versioning being added in 3.x mongoose and that it's generally all handled internally. It should be noted that I loaded this user data straight into mongo via json and the mongo commandline ( so it wouldn't have the versioning variable defined by default, but I suspect that mongoose would create it if it didn't find it... bad assumption?)</p>
  
  <p>EDIT: Sorry my simplified example had an error in it.</p>