mo
mo copied to clipboard
Decoding BSON values
Hello,
I would like to know if decoding bson values from MongoDB could be a feature of this amazing lib.
type User struct {
Name mo.Option[string] `bson:"name"`
}
error decoding key name: cannot decode string into a mo.Option[string]
I would to suggest to decode an empty string or none present key to None.
Thank you in advance.
Hi @davidbayo10
Sure. I suppose implementing BSON marshalers must be simple. Feel free to propose a PR.
I just checked the bson library from MongoDB driver. It seems the provide a codec registry: https://pkg.go.dev/go.mongodb.org/mongo-driver/bson/bsoncodec
I think we should create a sub-package under github.com/samber/mo/bson
in order to not embed go.mongodb.org/mongo-driver
into global go.mod
and keep it lightweight. That package would later be imported using import _ "github.com/samber/mo/bson"
. WDYT ?