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
315 stars 81 forks source link

Error when serializing date #132

Closed joandvgv closed 7 years ago

joandvgv commented 7 years ago

Hi there.

I'm using mongify to migrate date from my sql work. Where a field date is created in table 'servicios' Mongify documentation states that a date field will be converted to a time format

:date # Will be converted to a Time format (Date is not currently supported in the Mongo ruby driver)

Yet, I get the following error while performing process database.config > translation.rb: C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bson-1.12.5/lib/bson/bson_c.rb:20:inserialize': Date is not currently supported; use a UTC Time instance instead. (BSON::InvalidDocument`

Am I doing something wrong? How do I convert mysql Date type to UTC time? Why is it not performing as expected (converting date to a Time format)

Thanks in advanced for your support!

anlek commented 7 years ago

Odd, try changing the type to :datetime and see if it works

joandvgv commented 7 years ago

I ended up changing my sql date field to string. I'll try tomorrow with date time and let you know.

I know got a problem with embed in function

I got a table named "clientes" and other named "carros". Every client can have multiples cars associated.

In my sql I had an additional table with a car ID an a client ID.

I see in your examples for embedding you embed on a referencing fields, but I don't have any columns referencing clients in my table "carros" So I just do table "carros" embed in -> "clientes" but it's not working. Output says embedded 1/1 but got only clients collection with basic fields associated.

I have tried what you suggested on previous posts about embedding as "array", but don't know a workaround about the referencing issue. Thanks!

joandvgv commented 7 years ago

I was able to solve my problem by:

  1. Creating a new table named "cars" which will have all the data from "carros", plus an id referencing client primary key "cedula"

  2. Joining table "cc" which has primary key from "carros" and primary key from "clientes" with "carros" So I can have ced field.

  3. Inserting data from JOIN result.

  4. In translation.rb file, ignoring data from original table and embedding new one as follows:

`table "carros", :ignore => true

table "cars", :embed_in => 'clientes',
:on => 'c_ced' do column "id", :key, :as => :integer column "marca", :string column "modelo", :string column "placa", :string column "color", :string column "c_ced", :string end `

Hope this helps anyone.

Also, about the original question, I was able to solve my problem abou field date not beign converted to a time format by changing the field type to string. Later in Mongo, you can convert it back.

anlek commented 7 years ago

Thank you for sharing your solution! Good luck with your project!