title: make couchDB calculate an average and keep it up to date when adding values
body: <p>Is it possible to make couchDB (Cloudant) calculate the average <code>rating</code>  value of each document ?
  If yes, how to do this in Cloudant ?</p>
  
  <p>Thanks.</p>
  
  <pre><code>{
    "_id": "2016-02-06T13:16:30.515Z",
    "_rev": "3-7521b9e21fbb58d5393a76d08b12ab12",
    "modelStrict": "Taj model",
    "ratings": {
      "2016-02-06T13:36:04.671Z": {
        "userEmail": "lourain@yaho.fr",
        "rating": 1,
        "sessionNumber": 0
      },
      "2016-02-06T13:46:04.671Z": {
        "userEmail": "louin@yaoo.fr",
        "rating": 3,
        "sessionNumber": 0
      },
      "2016-02-06T13:53:04.671Z": {
        "userEmail": "luin@yaoo.fr",
        "rating": 3,
        "sessionNumber": 0
      }, 
      "2016-02-06T13:47:04.671Z": {
        "userEmail": "loin@yaoo.fr",
        "rating": 5,
        "sessionNumber": 0
      }
    },
    "averageRating": ...
  }
  </code></pre>
  
  <p>And how to keep this averageRating up to to date when a rating is added ?</p>
  
  <p>An added rating looks like this:</p>
  
  <pre><code>    "2016-02-06T17:57:04.671Z": {
        "userEmail": "loin@yaoo.fr",
        "rating": 2,
        "sessionNumber": 10
      }
  </code></pre>