I develop Go code to work with MongoDB using mgo driver. First I developed it on Windows computer, and it worked just fine (with Mongo DB installation on the same Windows computer). Then I copied the source code to a Linux machine with its own installation of MongoDB, built it there, and it did not work. The problem is how it reads object "_id" from the database.
On Windows it is normal 12-byte ObjectId, similar to this (shown using bson.ObjectId.String() ):
user Id: ObjectIdHex("533f8c02023ab611d62dbafd")
But on Linux it is this:
user Id: ObjectIdHex("33756e46397a6842337659437139546a51")
Of course, I cannot use that object ID for references, etc. It is 17 bytes long.
One interesting thing is that on Windows, MongoDB shell shows ObjectId like this:
"_id" : ObjectId("533f8c02023ab611d62dbafd")
While on Linux like this:
"_id" : "3unF9zhB3vYCq9TjQ"
If I convert string "3unF9zhB3vYCq9TjQ" character by character in HEX format, it will be exactly "33756e46397a6842337659437139546a51". so, my understanding is that instead of base64-decoding the _id, mgo driver on Linux converts every byte of it into HEX format.
I guess I can figure out how re-encode it myself, but is it a known bug in mgo driver on Linux, or I am missing something here, like some configuration, etc.? I would like to keep my program portable.
Thanks.