title: apply update options without save for pre-validation - mongoosejs
body: <p>In any <em>webapp</em> i press a plus button and a value will be increased.
  When i hit the button fast the validation does not work, cause the validations does not prevent (excepted behavior, the value is not out of the validations range). But the value will be setted down further, cause the rest of the reqeust will be submitted.</p>
  
  <p><strong>Important:</strong> the update <code>options</code> are dynamically (for instance <code>$inc</code> or <code>$set</code>).</p>
  
  <h3>Current Code</h3>
  
  <pre><code>module.model.update({ _id: id }, options /* are dynamic */, { safe: true }, function (err, updatedDocument) {
      if (err) return respond(400, err);
  
      module.model.findOne({ _id: id }, function (err, foundDocument) {
          if (err) return respond(400, err);
  
          foundDocument.validate(function (err) {
              if (err) return respond(400, err);
  
              return respond(200, foundDocument); // callback method
          });
      });
  });
  </code></pre>
  
  <h3>First guess to prevent the problem</h3>
  
  <pre><code>module.model.findOne({ _id: id }, function (err, foundDocument) {
  
      foundDocument.set(options);
  
      foundDocument.validate(function (err) {
          if (err) return respond(400, err);
  
          foundDocument.save(function (err, savedDocument) {
              if (err) return respond(400, err);
  
              return respond(200, doc);
          });
      });
  });
  </code></pre>
  
  <p>...then the save just will preformed when the validation is valid.</p>
  
  <p>But there is a porblem: The <a href="http://mongoosejs.com/docs/api.html#document_Document-set" rel="nofollow"><code>set</code></a> method does not support <code>$inc</code> or other pseudo setters, or does it?</p>
  
  <p>I saw the possibility to use the <a href="http://mongoosejs.com/docs/api.html#document_Document-update" rel="nofollow">constructor of the update function (Show Code)</a>, but i don't know how to use it: <code>this.constructor.update.apply(this.constructor, args);</code></p>
  
  <p>Do you have any good practise for this problem ?</p>