Skip to content
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

Decoding BSON values #20

Open
davidbayo10 opened this issue Mar 2, 2023 · 1 comment
Open

Decoding BSON values #20

davidbayo10 opened this issue Mar 2, 2023 · 1 comment

Comments

@davidbayo10
Copy link

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.

@samber
Copy link
Owner

samber commented Mar 20, 2023

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@samber @davidbayo10 and others