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

From SQL Server to mongoDB - Creating Embeded Documents #151

Closed robertangeles closed 7 years ago

robertangeles commented 7 years ago

Hi fellow users of mongify and to you Andrew(@anlek) . I found mongify a couple of weeks ago and was thrilled that it can help us tremendously in moving our SQL Server data to mongoDB. I am very much from the world of RDBMS and doing my best to unlearn to learn the world of documents.

I already have a sandbox to play with and was wondering if I can ask for some assistance in creating translation files. I have read the getting started section but I may have overlooked or may have overthink how to do things the mongify way.

I have this simple table: SQL Server table

And I want to create a translation file to migrate it to mongodb collection: mongoDB collection

I would greatly appreciate your assistance.

Thanks!

Rob

anlek commented 7 years ago

Hey @robertangeles, If you have a database.config file setup, execute the command mongify translation database.config. This will go to your SQL database and grab all the tables and build a starter translation file.

From that point, you need to rewrite the translation to meet your needs.

Hope that helps, Andrew

robertangeles commented 7 years ago

HI @anlek! Thank you for the reply. I know you are a busy bee.

I am familiar with creating and processing translation files. What I am having issues with is how to structure it.

How can I create the translation file in a way where it will produce the structure of the document I have provided in my original post? My sincere apologies if I'm confusing you, I'm still trying to get my head around creating translations that embed documents. Initially, I would create it like the translation below but this will be a flat document. I would like the address details to be an embedded document.

table "properties" do column "propertyId", :string column "propertyName", :string column "addressLine", :string column "suburb", :string column "state"; :string column "postcode", :string column "status", :string column "subStatus", :string: end

Thanks!

Rob

anlek commented 7 years ago

Oh, I see, you only have one table and you're trying to restructure it. That's doable via before_save helper:

table "properties" do
  column "propertyId", :string
  column "propertyName", :string
  column "addressLine", :string
  column "suburb", :string
  column "state"; :string
  column "postcode", :string
  column "status", :string
  column "subStatus", :string

  before_save do |row|
    row.address = {}
    row.address['addressLine'] = row.delete('addressLine')
    row.address['suburb'] = row.delete('suburb')
    row.address['state'] = row.delete('state')
    row.address['postalcode'] = row.delete('postalcode')
    row
  end
end
anlek commented 7 years ago

Feel free to read more about before_save and other features via: http://www.rubydoc.info/gems/mongify/