dqstti8945 2014-04-12 07:14
浏览 42

Windows和Linux上通过mgo驱动程序对ObjectID的不同处理

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么