[GODRIVER-1657] Allow passing interface{} to Cursor.All Created: 17/Jun/20 Updated: 28/Oct/23 Resolved: 29/Jun/20 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | CRUD |
| Affects Version/s: | 1.3.4 |
| Fix Version/s: | 1.4.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | David Wen Riccardi-Zhu | Assignee: | Kriti Ravindran (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Linux x86_64 |
||
| Description |
|
Passing an interface{} to cursor.All results in a panic.
It would be great if cursor.All could unwrap the type underlying the interface{}, just like pipeline.All in mgo. Compare: For background: We usually wrap our DB driver in a package. We do this for a few reasons: to set defaults, add logging, and make contributing a little easier for engineers that are not full-time Go / backend engineers. With mgo, we were able to have Aggregate and Find functions that accepted an interface parameter, and then forwarded that parameter to pipeline.All. We are unable to do this with the official driver, which seems to be written with the expectation that the type will be passed in directly from the caller. I'm not a frequent user of reflect, but it seems I can implement the desired functionality by adding the following before line 183 in cursor.go:
This is pretty much the same code used in mgo's pipeline.All. With this code, my wrapper function is able to decode the passed in interface. |
| Comments |
| Comment by Divjot Arora (Inactive) [ 02/Jul/20 ] |
|
Commit link: https://github.com/mongodb/mongo-go-driver/commit/3b6055918ea92e08ac2aab56b1533a30551b2c6c |