Jason Xu
Jason Xu

Reputation: 2963

Mapping Mongodb ObjectId to Mysql ID Field

I have an mongodb based application which use 12 byte objectid as primary key and as user id, and I have another Django app using Mysql, and need to inherits the user id generated from mongodb (inherit means not create new id but just store id which come from mongodb, and use it as a foreign key anywhere possible).

What's the best solution of,

  1. what data type to be used to express Mongo Object Id in mysql? binary(12)?
  2. considering using Django, any extra plugin needed for using binary(12)?
  3. or any solution different from the above?

Thanks.

Upvotes: 4

Views: 4641

Answers (1)

Sicco
Sicco

Reputation: 6281

I have been using both BINARY(12) and VARCHAR(24) to store MongoDB's ObjectIds in MySQL. BINARY(12) uses less disk space, but you need to use HEX() to work with it as a string.

Upvotes: 9

Related Questions