Mongify - MonogoDB _id 字段值覆盖 MySQL id 主键字段值

Mongify - MonogoDB _id Field Value Overwrites MySQL id Primary Key Field Values

我正在使用 Mongify 将 MySQL 数据转换为 MongoDB。但是,我在 MySQL table 中有 id 字段作为 primary_key 但是在 mongify 之后它会用默认 MongoDB _id 值覆盖,即 "_id" : ObjectId("58369f006ee5c61b9400000e"), 我不想覆盖这个我需要 MySQL 中 id 列中的 primary_key 完全相同的值到 MongoDB _id 中,看起来像这样:

MySQL id: 123 应转换为 MongoDB"_id" : ObjectId("123"),

这是我的翻译文件 table

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

提前致谢。

我刚刚找到了 Mongify 中已有的解决方法 docs

添加这个

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

所以 users table 的完整交易脚本看起来像

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

还是谢谢你。