[GODRIVER-1111] type conversion like mgo Created: 05/Jun/19 Updated: 07/Jun/19 Resolved: 07/Jun/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | BSON |
| Affects Version/s: | 1.0.2 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Pierre Durand | Assignee: | Divjot Arora (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
With the old mgo library, type conversion were handled automatically. I have 2 issues while migrating an application:
The BSON library returns an error, because the types don't match. I understand that the mapping should be strict, and personally I think it's a good practice. However I don't have full control over the data managed by my company. Some developers use programming language with poor typing (JS), and they don't care about the type of data they insert. With the old mgo library, my code was working fine, because it was doing the type conversion for me. See https://github.com/globalsign/mgo/blob/eeefdecb41b842af6dc652aaea4026e8403e62df/bson/decode.go#L820-L829 I understand if you don't want to change the code of the official MongoDB driver. |
| Comments |
| Comment by Divjot Arora (Inactive) [ 07/Jun/19 ] |
|
pierrre Thank you for the BSON suggestions. This behavior can be achieved with a custom registry (seems like you'd want a custom codec to unmarshal strings specifically for the issues you listed). We do have plans to create a set of codecs to provide mgo-compatibility later this quarter. You can track https://jira.mongodb.org/browse/GODRIVER-226 for that work. |
| Comment by Pierre Durand [ 06/Jun/19 ] |
|
After some investigation, I think that I can implement the old behavior with a custom registry. |