Details
-
Bug
-
Resolution: Done
-
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?