title: CouchDB for event sourcing
body: <p>I've been playing with CouchDB for a week now and I love it; it's probably the most convenient NoSQL DB I've seen so far.</p>
  
  <p>Now I'm considering using it (Cloudant, actually) to manage entities in an event sourcing fashion, but I have doubts that CouchDB is actually suitable for such a case...</p>
  
  <p>Let's say I want to manage a "type" whose "projection" would be something like:</p>
  
  <pre><code>{
      "field1":"some-string",
      "field2":["an","array","of","strings"]
  }
  </code></pre>
  
  <p>I would insert events like:</p>
  
  <pre><code>{ "type":"set-field1", "value":"another-string" }
  { "type":"remove-field2", "value":"strings" }
  { "type":"add-field2", "value":"bugs" }
  </code></pre>
  
  <p>and as you guess, I would expect the "projection" to become:</p>
  
  <pre><code>{
      "field1":"another-string",
      "field2":["an","array","of","bugs"]
  }
  </code></pre>
  
  <p>Now I'm still a noob in map/reduce, but my intuition is that:</p>
  
  <ul>
  <li>the reduce would have to be some pretty elaborate JS and all the docs I've read strongly recommend to use the built-ins reduce functions exclusively</li>
  <li>even though the map is executed incrementally on objects being added/updated (and somehow deleted), I guess that the reduce is always executed on the full output of the map, which makes the previous point even worse...</li>
  </ul>
  
  <p>That's where I am right now. The only thing I've found concerning CouchDB in an event sourcing approach is <a href="http://docs.cloudant.com/guides/eventsourcing.html" rel="nofollow" title="this article">this article</a> (which only uses the built-in _sum reduce, of course!). So I would appreciate any advises/opinions from CouchDB power users about the relevance of my (modest) analysis.</p>
  
  <p>Thanks</p>