开发者

Move MongoDB data from Staging server to Production

I have 500,000 documents inside a collection on a staging server, I need to mo开发者_如何学Cve these documents to the production server.

What is the best way to move this data, can I let mongodb replicate it from staging to production, do I move the data files or do I do an export and re-import?


  • To dump a collection do

    mongodump -d dbname -c collectionname

    On a Windows machine this will create a dump folder under the Mongo 'data' folder with bson files

  • To restore on a remote host

    mongorestore -h hostname -d dbname -c collectionname dump\dbname\collectionname.bson


Take a look at the mongodump and mongorestore tools. If you only want some of the documents in the collection you can use the --query parameter.


you can also run a db.copyDatabase command from the console or in your app.

http://docs.mongodb.org/manual/tutorial/copy-databases-between-instances/


Its simple.

In the destination server > mongo shell > run

db.copyDatabase( source_db_name, destination_db_name, source_hostname, username, password)


The data files are not per collection so that's out if you want to copy a collection not a full db. If it's per DB you can copy the database files just fine. I am not sure 32 bit vs 64 bit... but i guess you are 64 bit if you run MongoDB.

Now, if the collection exists on both and need to merge then be superb careful to keep _id unique. mongoimport/mongoexport is your friend.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜