Skip to content

Instantly share code, notes, and snippets.

@kagemusha
Created November 16, 2012 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagemusha/4090276 to your computer and use it in GitHub Desktop.
Save kagemusha/4090276 to your computer and use it in GitHub Desktop.
mongodump mongorestore - base case
Ref:
http://docs.mongodb.org/manual/reference/mongodump/
mongorestore --collection people --db accounts dump/accounts/
Say you want to transfer your local mongo dbs to another machine. One way using dump and restore is:
1. run mongodump on old machine
- this will put all your mongo dbs in a directory called dump in the current dir
- for instance if you have one db called mydb, will have a dir dumb/mydb with your data
2. zip and transfer dump dir to new machine
3. after unzipping run mongorestore from the dir containing dump:
- e.g. to restore the db in step 1, do:
mongorestore --db db_to_restore dump/mydb
(where of course you sub your db name for mydb)
Note:
mongorestore will create a new db in named db doesn't exist. If it exists, it will add records which don't already exist. It will not update existing records.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment