Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1424

Question - How to perform partial update on a collection?

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      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?

      Attachments

        Activity

          People

            divjot.arora@mongodb.com Divjot Arora (Inactive)
            gabriele.bassi@yahoo.it Gabriele Bassi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: