[GODRIVER-555] Database.RunCommand should return *DocumentResult Created: 15/Sep/18 Updated: 28/Oct/23 Resolved: 27/Nov/18 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | Administrative Commands |
| Affects Version/s: | None |
| Fix Version/s: | 0.1.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | David Golden | Assignee: | Isabella Siu (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | beta | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Epic Link: | Finalize mongo API | ||||||||
| Description |
|
For consistency with how FindOne and similar "single result" methods work, the Database.RunCommand method should return a *DocumentResult. |
| Comments |
| Comment by Githook User [ 27/Nov/18 ] |
|
Author: {'name': 'Isabella Siu', 'email': 'isabella.siu@10gen.com'}Message: Change-Id: Ica6d147723772fddc89032264d9d6f4d48dcc914 |
| Comment by Kristofer Brandow (Inactive) [ 24/Sep/18 ] |
|
I think this is a valid use case, but I think we should potentially rename DocumentResult to something else. Perhaps SingleResult? |
| Comment by David Golden [ 17/Sep/18 ] |
|
That it's a single iteration of a cursor is an implementation detail. Semantically, it's a BSON-library agnostic result abstraction that can be unmarshalled into a desired type. Any time there's a "single document" result, we should be providing the same semantics to users for familiarity. Consider what's required to unmarshall a bson.Reader into a user-defined struct: cast Reader back to bytes and run it through the Unmarshal function. That's not user friendly (nor obvious). Or, if you don't want to cast (which is a code smell), bson.Marshal it to bytes and then bson.Unmarshal it back. That's even less user-friendly. Worst case, DocumentResult could be an interface and you can have two implementations – one for a single doc from the OP_REPLY/OP_MSG and one that grabs the first result from a cursor. However, I think it would be easier to make it abstract a single document and eagerly pull the document from the cursor when constructing the DocumentResult in the FindOne case. |
| Comment by Kristofer Brandow (Inactive) [ 17/Sep/18 ] |
|
The *DocumentResult won't operate in the same way if we add it to RunCommand. The *DocumentResult is essentially a helper so you don't have to do a single iteration of a cursor. *RunCommand won't always return a cursor, so I don't think it makes sense here. Also, we don't want to imply that it works like the other single result things, e.g. if you call FindOne from a *RunCommand it won't properly unmarshal your result since it's wrapped in a cursor. |