[GODRIVER-30] Implement MGO API Created: 26/May/17  Updated: 17/Jul/20  Resolved: 17/Jul/20

Status: Closed
Project: Go Driver
Component/s: Administrative Commands, CRUD
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Craig Wilson Assignee: Unassigned
Resolution: Won't Fix Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to GODRIVER-916 Cursor method to decode all results i... Closed
Epic Link: mgo migration tool

 Comments   
Comment by David Bartley [ 06/Apr/19 ]

I can understand the reasoning around the second point, though I'm not sure that users of the go driver would necessarily care about the distinction? As a compromise, could Find do the same thing as RunCommand and FindOne with SingleResult, and pre-set the Cursor error? That way users can write less verbose code, and for anyone that does care about the distinction (i.e. they want to know find failed vs some subsequent getMore) they have the option of checking the return of Find itself?

Comment by David Bartley [ 06/Apr/19 ]

Ah, I see ("If there was an error from the operation that created this SingleResult then the error will be returned."). It might be worth adding something to the godoc for "Err" to clarify that you'd only need to call that method if you didn't care about the output?

Comment by Kristofer Brandow (Inactive) [ 05/Apr/19 ]

To your second point, bartle, during the design process we decided that an error to create a cursor was a different category of error from an error with the cursor itself, which is why they are two different errors (this is similar to why Decode provides it's own error, separate from Cursor).

To your third point, I'm not sure what you mean. RunCommand only returns returns a mongo.SingleResult, on which you can call Decode. The Err method on mongo.SingleResult should only be used if you don't want to do anything with the resulting document and only want the error. The RunCommandCursor method returns a Cursor and an error, but that's to align with the reasoning above.

Comment by Scott L'Hommedieu (Inactive) [ 02/Apr/19 ]

Added this new issue based on the first bullet from bartle 

Comment by David Bartley [ 22/Mar/19 ]

We recently tried to migrate from mgo to mongo-go-driver and discovered a few sharp edges/usability problems.

  • There's no equivalent to mgo's All method; instead you have to walk the cursor, decode, and append to a slice; this requires 3 error checks and a defer (to close the cursor), instead of 1 error check and no defers with mgo.
  • Why does Find return an error instead of just pre-setting an error on the returned Cursor?  That's what mgo does and would reduce the number of error checks from 2 to 1.
  • RunCommand should just accept an output argument, like mgo.  As is, using RunCommand requires checking 2 errors (the function itself and Decode) instead of 1.
Comment by Mihai B [ 12/Jul/18 ]

It's worth to note that the "official" API is near unusable due the lack of documentation and abuse of interface{}.

Generated at Thu Feb 08 08:33:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.