2016-11-24 70 views
0

我正在使用Mongify將MySQL數據轉換爲MongoDB。然而,我在MySQL表id字段primary_key但經過mongify它默認的MongoDB覆蓋_id值,即"_id" : ObjectId("58369f006ee5c61b9400000e"),我不想改寫這個我需要的primary_key完全相同值在MySQL id列到MongoDB的_id事情是這樣的:Mongify - MonogoDB _id字段值覆蓋MySQL ID主鍵字段值

MySQL的id: 123應該轉換成MongoDB的作爲"_id" : ObjectId("123"),

這裏是用戶表的我的翻譯文件

table "users" do 
    column "id", :key, :as => :integer 
    column "username", :string 
    column "password", :string 
    column "email", :string 
    column "first_name", :string 
    column "last_name", :string 
    column "dob", :date 
    column "gender", :boolean 
    column "status", :integer 
    column "created", :datetime 
    column "modified", :datetime 

end

在此先感謝。

回答

0

我才發現這是已經存在於Mongify解決辦法docs

添加這

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

所以對於users表完整transaltion腳本會是什麼樣子

table "users" do 
    before_save do |row| 
    row._id = row.delete('pre_mongified_id') 
    end 
    column "id", :key, :as => :integer 
    column "username", :string 
    column "password", :string 
    column "email", :string 
    column "first_name", :string 
    column "last_name", :string 
    column "dob", :date 
    column "gender", :boolean 
    column "status", :integer 
    column "created", :datetime 
    column "modified", :datetime 
end 

謝謝無論如何。