mo icon indicating copy to clipboard operation
mo copied to clipboard

Decoding BSON values

Open davidbayo10 opened this issue 2 years ago • 1 comments

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.

davidbayo10 avatar Mar 02 '23 17:03 davidbayo10

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 ?

samber avatar Mar 20 '23 18:03 samber