Skip to main content

Data Migration from Development to Production environment

We have to migrate data from dev to Prod( Sharded Environment).

We will use mongoDump and mongoRestore utility.



MongoDump:  Used to create binary export of the contents of the database. It does not include index data. It requires to rebuild index after restoring the data.

Futher Reference from MongoDB 


MongoRestore: Used to import binary content from dump to the MongoDB instance.

Further Reference from MongoDB



Take dump from Dev Server as:



mongodump  --host  dev_hostname:port  -u user -p ****** --authenticationDatabase db_name_where_authentication_checks --db dbname --collection collection_name 


 A dump folder created includes bson file.

SCP that file to the Production server

Then restore as:

 mongorestore --host prod_hostname:port  -u user -p ******  --authenticationDatabase db_name_where_authentication_checks  --collection collection_name --db dbname  path_to_dump_bson 







Comments

Popular posts from this blog

Recover Recently Deleted documents

use recoverDoc ; for ( i = 0 ; i < 100 ; i ++){ db . col1 . insert ({ _id : i })}; for ( i = 100 ; i < 200 ; i ++){ db . col1 . insert ({ _id : i , name : "some_x_name" })}; > db . col1 . remove ({ "name" : "some_x_name" }) WriteResult ({ "nRemoved" : 100 }) use local ; db . oplog . rs . find ({ op : "i" , ns : "recoverDoc .col1" , "o.name" : "some_x_name" }). count (); 100 db . oplog . rs . find ({ op : "i" , ns : "recoverDoc .col1 " , "o.name" : "some_x_name" }, { "o" : 1 }); { "o" : { "_id" : 100 , "name" : "some_x_name" } } { "o" : { "_id" : 101 , "name" : "some_x_name" } } { "o" : { "_id" : 102 , "name" : "some_x_name" } } { "o" : { ...

Mongod log is growing too large.

We have log append true in config file. Every day log is appended to the single log file. We are facing issue in space and we were also not able to purge the log file completely. So we need logs file for every day, if we have space issue then we can remove the old logs. Only thing we need to do is: In config file make sure we have: logappend = true Then login to mongo shell, run the below command against the admin database. use admin db.runCommand({logRotate:1})