title: using upsert in array search in mongodb
body: <p>I am working on mongodb and making a database structure as:</p>
  
  <pre><code>{
          "_id" : ObjectId("5e9fef05c0228a50befba0d7"),
          "name" : "sanghm",
          "id" : "3456",
          "dep" : {
                  "dep1" : "ops",
                  "dep2" : "analytics"
          },
          "data" : [
                  {
                          "date" : "25-apr-2020",
                          "log" : [
  
                                  {
                                          "machine" : "windows-user1",
                                          "task" : "excel",
                                            "time": "10:00am"
                                  }
                                  {
                                          "machine" : "windows-user1",
                                          "task" : "email",
                                            "time": "11:00am"
                                  }
  
                          ]
                  }
          ]
  }
  </code></pre>
  
  <p>to push every new task on database, i'm using a query like</p>
  
  <pre><code>date = '25-apr-2020'
  
  db.inventory.update({id:'3456'},{{$push:{'data.$[t].log':{machine:'windows-user1',task:'new task',time:'3:00pm'}}},{arrayFilters:[{"t.date":date}]}})
  </code></pre>
  
  <p>this query pushing new task to date array.
  if in case the date changes to '26-apr-2020' then can we use same query to first add new date filed and then push data for the same. </p>
  
  <p>i have read about <code>{upsert: true}</code> but dont know how  to use it in my case</p>