go.uuid icon indicating copy to clipboard operation
go.uuid copied to clipboard

Added support for marshaling/unmarshaling of MongoDB's BSON UUID binary format

Open inliquid opened this issue 6 years ago • 4 comments

Added support for marshaling/unmarshaling of MongoDB's BSON UUID binary format.

inliquid avatar Jan 02 '19 18:01 inliquid

Coverage Status

Coverage decreased (-7.03%) to 90.49% when pulling 186ab3502a6e4f26a34dbece9e80c1a79ad7ad92 on inliquid:master into b2ce2384e17bbe0c6d34077efa39dbab3e09123b on satori:master.

coveralls avatar Jan 02 '19 18:01 coveralls

Coverage Status

Coverage decreased (-7.03%) to 90.49% when pulling d43747066e65157add02533fb55e815b9fa07859 on inliquid:master into b2ce2384e17bbe0c6d34077efa39dbab3e09123b on satori:master.

coveralls avatar Jan 02 '19 18:01 coveralls

I would disagree regarding this pr since there are different libraries for handling BSON format (eg mongo-go-driver and mgo) so it's better to have this implementation outside the package scope Will update later with my solution on stack overflow The method you are implementing is specific to mgo

EDIT:

You can find a solution to this problem on the following stackoverflow link https://stackoverflow.com/questions/50889485/how-should-i-handle-uuid-fields-using-mgo/54094766#54094766

saniales avatar Jan 20 '19 10:01 saniales

@saniales the above stackoverflow link covers different and quite too much particular case (it's close but not the same, also please pay attention that proposed solution covers both Mongo's Legacy UUID and new UUID binary kinds). And yes of course it's possible to embed UUID into your own struct and write Marshaler/Unmarshaler for that struct. However, if you try to do so you'll find that code becomes more complex, less clear, and overall it seems strange when support for JSON comes out of the box, but for BSON you have to reinvent the wheel. In my project I did this trick with embedded struct initially, but later moved to forked version of UUID implementation. From the other hand, I understand concerns for external dependencies.

inliquid avatar Feb 05 '19 20:02 inliquid