Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
1.0.2
-
None
Description
With the old mgo library, type conversion were handled automatically.
I have 2 issues while migrating an application:
- MongoDB field is a number, Go struct field is a string
- MongoDB field contains null, Go struct field is a string
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.