2016-11-24 68 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 

谢谢无论如何。