Using mgo
, it seems that best practice is to set object ids to be bson.ObjectId
.
This is not very convenient, as the result is that instead of a plain string
id the id is stored as binary in the DB. Googling this seems to yield tons of questions like "how do I get a string out of the bson id?", and indeed in golang
there is the Hex()
method of the ObjectId
to allow you to get the string.
The bson becomes even more annoying to work with when exporting data from mongo to another DB platform (this is the case when dealing with big data that is collected and you want to merge it with some properties from the back office mongo DB), this means a lot of pain (you need to transform the binary ObjectId to a string in order to join with the id in different platforms that do not use bson representation).
My question is: what are the benefits of using bson.ObjectId
vs string
id? Will I lose anything significant if I store my mongo
entities with a plain string id?