I noticed when trying to insert an complex data type into a mongodb using Go without having MarshalBSON
implemented, it falls back to MarshalJSON
and inserts the struct correctly as a document in mongodb.
However, when I then try to retrieve that same document with only UnmarshalJSON
implemented and no UnmarshalBSON
it can't decode it back since it can't find a decoder.
I opened an issue on the library in question (https://github.com/paulmach/orb/issues/122#issue-1571013323) but it seems weird behaviour that it uses a fallback in one way but not in another way.
Also having both MarshalBSON
and UnmarshalBSON
implemented, referring them to the JSON equivalents, gives some more weird behaviours.
Any clues on why that is?
2nd question, what should be the implementation difference if I'm going to implement this for BSON instead of JSON? Since insert works with JSON, but retrieving doesn't?