[GODRIVER-743] UpdateOne and UpdateMany should return error when update parameter is of zero length Created: 03/Jan/19 Updated: 23/Jan/19 Resolved: 23/Jan/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | CRUD |
| Affects Version/s: | 0.1.0 |
| Fix Version/s: | 0.3.0 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | ollevche | Assignee: | Divjot Arora (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Ubuntu 18.04 |
||
| Attachments: |
|
| Description |
|
The UpdateOne and UpdateMany methods do not ensure that the update parameter has at least one modifier. Update the ensureDollarKey method to return an error if there are no modifiers provided. (original description below) mongo.UpdateOne() erases all fields from a document matched by a filter when update interface is bson.D{} with zero length. That behavior is unwanted in my opinion (i've lost some data). Mongo shell acts differently (just returns an error 'the update operation document must contain at least one atomic operator'). I didn't check Update() and UpdateMany() but these ones may act the same as UpdateOne(). |
| Comments |
| Comment by Githook User [ 23/Jan/19 ] |
|
Author: {'email': 'divjot.arora@10gen.com', 'name': 'Divjot Arora', 'username': 'divjotarora'}Message: Disallow empty update documents. Change-Id: I57ef34e7ce9368128c560fef056eff1ccede9e3b |
| Comment by Kristofer Brandow (Inactive) [ 08/Jan/19 ] |
|
jeff.yemin the driver does support that, but there's a bug when there are no elements provided. I'll update this ticket and schedule it. |
| Comment by Jeffrey Yemin [ 08/Jan/19 ] |
|
Looks like the driver does not conform to this section of the CRUD specification: https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#update-vs-replace-validation.
The driver should be reporting this as an error and not sending the operation to the server. |
| Comment by ollevche [ 08/Jan/19 ] |
|
Yes, sure. In addition to the code, i added screenshots of the matched document before and after a function call. Something like that will erase all fields (except '_id' field) from a matched document: id, _ := primitive.ObjectIDFromHex("5c346258740d8e1c1c504455") db.Collection("students").UpdateOne(nil, filter, bson.D{}) |
| Comment by Kristofer Brandow (Inactive) [ 07/Jan/19 ] |
|
Hi ollevche, Can you please provide a working code example of this? Thanks, Kris |
| Comment by ollevche [ 07/Jan/19 ] |
|
@kris.brandow it's a typo, sorry. I'm using the latest one (0.1.0). |
| Comment by Kristofer Brandow (Inactive) [ 04/Jan/19 ] |
|
Hi ollevche, Can you upgrade to the latest beta (0.1.0) and try again to see if the problem persists? Thanks, Kris |
| Comment by ollevche [ 03/Jan/19 ] |
|
I'm using 0.0.10 version (not a 0.0.15). |