0

I want to migrate from MySQL to MongoDB.

In MySQL, PKs are integer. I want to cast them into ObjectID

When I try:

mongo.ObjectID(theInteger)

altough theInteger is same, results are different.

How can I do that?

Burak
  • 5,706
  • 20
  • 70
  • 110

2 Answers2

1

ObjectId is a hexadecimal, 24-byte chars type from MongoDB. In other words, you can't cast from a int.

The best you could do to maintain your MySQL data structure is use your MySQL PK in _id field, you'll have no trouble with this.

gustavohenke
  • 40,997
  • 14
  • 121
  • 129
  • Yes, but I will have troubles about it. For example, _id cannot auto_increment when insert. Am I wrong? – Burak Feb 27 '13 at 07:03
  • No, you're right. See here: http://www.mongodb.org/display/DOCS/How+to+Make+an+Auto+Incrementing+Field – gustavohenke Feb 27 '13 at 11:27
0

ObjectId is a special type of mongodb, but if you just want to migrate, you can store integer id of mysql to mongodb's '_id'.

jianpx
  • 3,190
  • 1
  • 30
  • 26