title: Extract values from fields in an array of JSON objects
body: <p>I have a collection in MongoDB with many documents that have the same structure.</p>
  
  <p>When I perform a find query with some filters over the collection with this code:</p>
  
  <pre class="lang-js prettyprint-override"><code>Comment.find(
          {
              "data.time.s": {
                  "$gte": "2019-05-13",
                  "$lte": "2019-05-27"
              }
          },
          {
              "data.iaqi.co.v": "$data.iaqi.co.v",
              "data.time.s": "$data.time.s",
              "_id": 0
  
          }, function (error, datos) {
  
              console.log(datos)
  
          });
  </code></pre>
  
  <p>I get the following output when I console.log(datos):</p>
  
  <pre class="lang-js prettyprint-override"><code>[
    { 
      "data" : {
          "iaqi" : {
              "co" : {
                  "v" : 3.2
              }
          }, 
          "time" : {
              "s" : "2019-05-14 12:00:00"
          }
      }
  },
  { 
      "data" : {
          "iaqi" : {
              "co" : {
                  "v" : 4.7
              }
          }, 
          "time" : {
              "s" : "2019-05-15 00:00:00"
          }
      }
    }
  ]
  </code></pre>
  
  <p>The array contains more than 2 objects, but for the purpose of the example I just put 2 of them.</p>
  
  <p>All of the objects in the array have the same structure, just the values of <strong>"v"</strong> and <strong>"s"</strong> change on each object.</p>
  
  <p>I just need to extract the values of fields <strong>"v"</strong> and <strong>"s"</strong> from each object and save them in a CSV file with this exact format:</p>
  
  <pre><code>Date,Value
  2019-05-14 12:00:00,3.2
  2019-05-15 00:00:00,4.7
  2019-05-17 05:00:00,1
  2019-05-19 20:00:00,2.3
  2019-05-28 08:00:00,33.4
  2019-05-28 10:00:00,18.8
  2019-05-28 12:00:00,11.5
  2019-05-28 13:00:00,12.4
  2019-05-29 06:00:00,6.4
  </code></pre>
  
  <p>Right now I'm doing some tests trying first to show the mentioned values from the array in console with a for loop (instead of just the console.log(datos) in the first code):</p>
  
  <pre><code>for (var i = 0; i &lt; datos.length; i++) {
                  console.log(datos[i]['data'['time'['s']]]);
              }
  </code></pre>
  
  <p>But I get the following output in the console:</p>
  
  <pre><code>undefined
  undefined
  </code></pre>
  
  <p>Obviously my syntax is incorrect, but I don't know where is the problem.<br>
  What would be the exact syntax to access the array and get the desired values?</p>
  
  <p>Thank you very much to everyone that can throw some light into this.</p>