title: Good way to store in mongo a large sets of different values of a device
body: <p>The scenario.</p>
  <p>A large set of devices connected to a back-end (1.000.000).</p>
  <p>Each few time the devices reports values, each value has got its time associated.</p>
  <p>I want to store all the values to read them in the future to make graphics.</p>
  <p>We need to locate each value to each second in the time.</p>
  <p>Propossed data structure in mongo:</p>
  <p>Option 1: (data as array of objects)</p>
  <pre><code>{
  device_id: [string],
  data: [
    {ts: [date], val1: [any], ..., valn:[any]},
  
    {ts: [date], val1: [any], ..., valn:[any]},
  ]
  }
  </code></pre>
  <p>Option 2 (data with date as property to object)</p>
  <pre><code>{
  device_id: [string],
  data: [
    &quot;2022-01-01T00:00:01&quot;: { val1: [any], ..., valn:[any] },
    ...
    &quot;2022-01-01T00:00:02&quot;: { val1: [any], ..., valn:[any] },
  ]
  }
  </code></pre>
  <p>Option 3 (data with date as property to array)</p>
  <pre><code>{
  device_id: [string],
  data: [
    &quot;2022-01-01T00:00:01&quot;: [[any], ..., [any]],
    ...
    &quot;2022-01-01T00:00:02&quot;: [[any], ..., [any]],
  ]
  }
  </code></pre>
  <p>Option 4:  (data with values and each document is a device_id with a time (the second))</p>
  <pre><code>{
  device_id: [string],
  ts:[date],  // &lt;-- each second
  data: {
     val1: [any], ..., valn:[any]
  }
  }
  </code></pre>
  <p>Option 5:  (data with values in array and each document is a device_id with a time (the second))</p>
  <pre><code>{
  device_id: [string],
  ts:[date],  // &lt;-- each second
  data: [[any], ..., valn:[any]] // each value has got a position
  }
  </code></pre>
  <p>Any other recomendation??</p>