title: MongoDB Get Average of each Filed-Child
body: <p>
  I am using javascript - mongoose. (beginner)
  Trying to calculate average of 'timeSpend' for each fields </p>
  
  <pre><code>{
      "_id" : ObjectId("5a2cca1c44ac67e8d5b8d2ff"),
      "total" : {
          "timeSpend" : "20"
      },
      "name_1" : {
          "timeSpend" : 9,
          "test" : "fail"
      },
      "name_2" : {
          "timeSpend" : "11",
          "test" : "fail"
      },
      "name_3" : {
          "timeSpend" : "8",
          "test" : "fail"
      }
      "__v" : 0
  },
  {
      "_id" : ObjectId("5a2cca1c44ac67e8d5b8d2ff"),
      "total" : {
          "timeSpend" : "10"
      },
      "name_1" : {
          "timeSpend" : 10,
          "test" : "fail"
      },
      "name_2" : {
          "timeSpend" : "5",
          "test" : "fail"
      },
      "name_3" : {
          "timeSpend" : "2",
          "test" : "fail"
      }
      "__v" : 0
  }
  </code></pre>
  
  <p>.... more documents...(every 10 minutes, new document will be saved)
  </p>
  
  <p>
  I am trying to calculate average 'timeSpend' for each fields 
  Example : </p>
  
  <pre><code>{
  total : 15,
  name_1 : 9.5,
  name_2 : 8,
  name_3 : 5
  }
  </code></pre>
  
  <p>I tried </p>
  
  <pre><code>(mongoose Schema).find({}).select('name_1' : 1, '_id':0)
  </code></pre>
  
  <p>then calculate average using loop, but I think it will be too expensive computing since document will be updated every 10 minutes (have to update average every 10 mins) </p>