title: Add new object inside array of objects, inside array of objects in mongodb
body: <p>Considering the below bad model, as I am totally new to this.</p>
  
  <pre><code>{
      "uid": "some-id",
      "database": {
          "name": "nameOfDatabase",
          "collection": [
              {
                  "name": "nameOfCollection",
                  "fields": {
                      "0": "field_1",
                      "1": "field_2"
                  }
              },
              {
                  "name": "nameOfAnotherCollection",
                  "fields": {
                      "0": "field_1"
                  }
              }
          ]
      }
  }
  </code></pre>
  
  <p>I have the collection name (i.e database.collection.name) and I have a few fields to add to it or delete from it (there are some already existing ones under database.collection.fields, I want to add new ones or delete exiting ones).</p>
  
  <p>In short how do I update/delete "fields", when I have the database name and the collection name.</p>
  
  <p>I cannot figure out how to use positional operator $ in this context.</p>
  
  <p>Using mongoose update as</p>
  
  <pre><code>Model.update(conditions, updates, options, callback);
  </code></pre>
  
  <p>I don't know what are correct <code>conditions</code> and correct <code>updates</code> parameters.</p>
  
  <p>So far I have unsuccessfully used the below for model.update</p>
  
  <pre><code>conditions = {
      "uid": req.body.uid,
      "database.name": "test",
      "database.collection":{ $elemMatch:{"name":req.body.collection.name}}
  };
  updates = {
      $set: {
          "fields": req.body.collection.fields
      }
  };
  
  ---------------------------------------------------------
  
  conditions = {
      "uid": req.body.uid,
      "database.name": "test",
      "database.collection.$.name":req.body.collection.name
  };
  updates = {
      $addToSet: {
          "fields": req.body.collection.fields
      }
  };
  </code></pre>
  
  <p>I tried a lot more but none did work, as I am totally new.
  I am getting confused between $push, $set, $addToSet, what to use what not to?, how to?</p>
  
  <p>The original schema is supposed to be as show below, but running queries on it is getting harder n harder.</p>
  
  <pre><code>{
      "uid": "some-id",
      "database": [
          { //array of database objects
              "name": "nameOfDatabase",
              "collection": [ //array of collection objects inside respective databases
                  {
                      "name": "nameOfCollection",
                      "fields": { //fields inside a this particular collection
                          "0": "field_1",
                          "1": "field_2"
                      }
                  }
              ]
          }
      ]
  }
  </code></pre>