anlek / mongify

Mongify allows you to map your data from a sql database and into a mongodb document database.
http://github.com/anlek/mongify
MIT License
317 stars 82 forks source link

_id Field as Integer [Match _id with id field of MySQL] #120

Closed kamrankhatti closed 7 years ago

kamrankhatti commented 7 years ago

Hello -

I ran mongify script to migrate MySQL data into MonogDB which works fine. However, I have id field in MySQL tables as primary_key but after mongify it overwrites with default mongify _id i.e "_id" : ObjectId("58369f006ee5c61b9400000e"), I don't want to overwrite this I need exactly same value of primary_key in id column in MySQL inot MongoDB _id something look like this:

MySQL id: 123 should convert into MongoDb as "_id" : ObjectId("123"),

Any help?

kamrankhatti commented 7 years ago

Found the workaround which was already there in Mongify docs I missed that out :) just need to add

before_save do |row| row._id = row.delete('pre_mongified_id') end

This before_save event does not allow Mongify to overwrite MySQL id values.

Thanks anyways.

srizviOfficial commented 7 years ago

great, it works for me.