title: storing data as object vs array in MongoDb for write performance
body: <p><strong>Should I store objects in an Array or inside an Object with top importance given  Write Speed?</strong></p>
  
  <hr>
  
  <p>I'm trying to decide whether data should be stored as an array of objects, or using nested objects inside a mongodb document.</p>
  
  <p>In this particular case, I'm keeping track of a set of continually updating files that I add and update and the file name acts as a key and the number of lines processed within the file.</p>
  
  <p>the document looks something like this</p>
  
  <pre><code>{
    t_id:1220,
    some-other-info: {}, // there's other info here not updated frequently
    files: {
      log1-txt: {filename:"log1.txt",numlines:233,filesize:19928},
      log2-txt: {filename:"log2.txt",numlines:2,filesize:843}
    }
  }
  </code></pre>
  
  <p>or this</p>
  
  <pre><code>{
    t_id:1220,
    some-other-info: {},
    files:[
      {filename:"log1.txt",numlines:233,filesize:19928},
      {filename:"log2.txt",numlines:2,filesize:843}
    ]
  }
  </code></pre>
  
  <p>I am making an assumption that handling a document, especially when it comes to updates, it is easier to deal with objects, because the location of the object can be determined by the name; unlike an array, where I have to look through each object's value until I find the match.</p>
  
  <p>Because the object key will have periods, I will need to convert (or drop) the periods to create a valid key (<code>fi.le.log</code> to <code>filelog</code> or <code>fi-le-log</code>).
  I'm not worried about the files' possible duplicate names emerging (such as <code>fi.le.log</code> and <code>fi-le.log</code>) so I would prefer to use Objects, because the number of files is relatively small, but the updates are frequent.</p>
  
  <p>Or would it be better to handle this data in a separate collection for best write performance...</p>
  
  <pre><code>{
      "_id": ObjectId('56d9f1202d777d9806000003'),"t_id": "1220","filename": "log1.txt","filesize": 1843,"numlines": 554
  },
  {
      "_id": ObjectId('56d9f1392d777d9806000004'),"t_id": "1220","filename": "log2.txt","filesize": 5231,"numlines": 3027
  }
  </code></pre>