Question - How to perform partial update on a collection?

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Hi to all

      I would like to know how to perform a partial update / new insert on a collection?

      I have a update end point in patch that contains only some property of a collection with different kind of properties.

      Example i have a collection like this

      https://jsoneditoronline.org/?id=5d1cb75ba2de4626ab2a4628e29b955e

      Update end-point request body

      https://jsoneditoronline.org/?id=81f6bbd30bab4349964d692fc3b374ee

       

      Update query in go:

       var docs models.Events var docs models.Events if err = json.Unmarshal(bodyBytes, &docs); err != nil { return nil, err }
       
      newObj := bson.M{"$set": docs} newObj := bson.M{"$set": docs}
       result, err := collection.UpdateOne(context.Background(), bson.M{"_id": _id}, newObj) if err != nil { return nil, err } fmt.Print(result.ModifiedCount)
      

      In this case all old content of assets are deleted.

      Is there a way to perform a partial update / insert without deleting old records?

            Assignee:
            Divjot Arora (Inactive)
            Reporter:
            Gabriele Bassi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: