Here I am migrating the Postgresql database to Mongodb with the help Mongify. 

If you check my postgres db, you can see a table named “rep_test” and the data inside the table.

[color-box color=“green”]

postgres=# \dt

List of relations

Schema |   Name   | Type  |  Owner   

——–+———-+——-+———-

public | rep_test | table | postgres

(1 row)

[/color-box]

[color-box color=“blue”]

postgres=# select * from rep_test;

      test       


data one

some more words

lalala

hello there

blahblah

(5 rows)

[/color-box]

Now for the db migration, you need to install the Mongify.

[color-box color=“green”]

gem install mongify

Then you need to create a file named “database.config”

For eg:-

root@locahost:~# cat database.config

_sqlconnection do

  adapter     ”postgresql”

  host           ”localhost”

  username  “postgres”

  password  “postgres123”

  database  “postgres”

end

_mongodbconnection do

  host      “localhost”

  database  “postgres”

end

[/color-box]

Then, you need to check if the database.config file is correct and the connections are working fine. You can check this by the below command:

[color-box color=“blue”]

mongify check database.config

[/color-box]

If the adapter is missing, it will give an error and you need to install the adapter by running the below command:

[color-box color=“green”]

gem install activerecord-postgresql-adapter

[/color-box]

Now, you need to run the translation command

[color-box color=“blue”]

mongify translation database.config > translation.rb

[/color-box]

Now, you can tell the mongify to move the data to mongodb. 

[color-box color=“green”]

mongify process database.config translation.rb

[/color-box]

Now, Verify everything is migrated to your Mongodb

[color-box color=“blue”]

show collections

rep_test

system.indexes

db.rep_test.find()

{ “_id” : ObjectId(“5645f3f000286643c4000001”), “test” : “data one” }

{ “_id” : ObjectId(“5645f3f000286643c4000002”), “test” : “some more words” }

{ “_id” : ObjectId(“5645f3f000286643c4000003”), “test” : “lalala” }

{ “_id” : ObjectId(“5645f3f000286643c4000004”), “test” : “hello there” }

{ “_id” : ObjectId(“5645f3f000286643c4000005”), “test” : “blahblah” }

[/color-box]