title: How can I update multiple nested fields in an array of documents
body: <p>I want to update one of the documents CLIENTDATA USING _id and clientID  as the filter keys how can I update it and is their any method through aggregation. How can I update swapnil name to something else using id and clientID as my filters </p>
  
  <pre><code>//UpdateClient is used to update clientData
  func UpdateClient(Data structure.ClientDataUpdate) bool {
      connection := GetConnection()
      if connection == nil {
          return false
      }
      collection := connection.Database("IAGENT").Collection("CLIENTDATA")
      filter := bson.M{"$and": []interface{}{bson.M{"_id": Data.ID}, bson.M{"clientData.clientID": Data.ClientID}}}
      update := bson.M{"$set": bson.M{"clientData.name": Data.Name, "clientData.policy": Data.Policy, "clientData.expiryDate": Data.ExpiryDate,"clientData.metaData":Data.Metadata,"clientData.mobile":Data.Phone}}
      _, err := collection.UpdateOne(context.TODO(), filter, update)
      if err != nil {
          fmt.Println("updating the Data", err)
          return false
      }
      return true
  }
  </code></pre>
  
  <p>Here is the image of my MongoDB database with the above collection.</p>
  
  <p><a href="https://i.stack.imgur.com/Ckxhw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ckxhw.png" alt="enter image description here"></a></p>