title: Is it possible to add fields to a document in a CouchDB validation function?
body: <p>One of the things that is lost in the move to CouchDB is the ability to have default values for a field. For example, in an SQL database you can have a field called <code>date</code> that defaults to <code>now()</code>. Is it possible to do something similar in CouchDB?</p>
  
  <p>From what I can tell, the only piece of code that gets run on every create and update operation is the <code>validate_doc_update</code> method of a design document. However, when we've tested it by creating a dummy validation, we can't get it to work. Here's a simple validation function that attempts to set the field <code>newDoc.foo</code>, but it never gets saved.</p>
  
  <pre><code>function(newDoc, oldDoc, userCtr) {
      newDoc.foo = "bar!";
  }
  </code></pre>
  
  <p>We've checked and verified that the <code>validate_doc_update</code> method is getting called, so it appears that if there a way to automatically add fields to a CouchDB document, using the validation function isn't the way to go. Any other suggestions?</p>