-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please support UnmarshalBSON and MarshalBSON serialization #168
Comments
|
Hi @myxtype. Thanks for pointing that. The corresponding PR that already implement the mentioned issue was created some time ago #92, but we haven't decided to merge it to the master branch as it introduces external dependence - we aim for dependency-free lib. We track this issue in our issue board and we will try to comes with a solution in v.1.3 release. |
You can work around this by registering a codec for encoding/decoding decimals as strings or some other format(mongodb's decimal128?) without adding a dependency or explicit support to this lib. https://pkg.go.dev/go.mongodb.org/mongo-driver/bson?tab=doc#MarshalWithRegistry You can even add it to the default registry if it is safe for your project. NOTE this requires the new official mongodb driver. I don't think mgo or the globalsign fork have any option for registering types/codecs. |
This can might be a valid workaround if we aiming for a dependency-free library. |
My temporary (and dirty) solution was to create another type extending the default, and update the value when insert in db type Product struct {
Price decimal.Decimal `bson:"price" json:"price"`
}
type MongoProduct struct {
Product
Price string `bson:"price" json:"price"`
}
func CreateProduct(p Product) {
var product = MongoProduct{}
product.Price = p.Price.String()
// insert in db
} |
Useful when using mongodb databases
The text was updated successfully, but these errors were encountered: