Skip to content

Instantly share code, notes, and snippets.

@tokisakiyuu
Last active December 4, 2024 08:56
Show Gist options
  • Save tokisakiyuu/73de96e48501968b695067cb3da6e017 to your computer and use it in GitHub Desktop.
Save tokisakiyuu/73de96e48501968b695067cb3da6e017 to your computer and use it in GitHub Desktop.
Transfer all data to another host with Mongodb (mongodump + mongorestore)

Dump (export data)

mongodump --db=example \                                                                                      
  --out=example-dump \                                                                                        
  --uri="mongodb://user:[email protected]:27017/?authSource=admin&directConnection=true"
mongodump --db=<db-name> --out=<out-dir> --uri="<mongodb-uri>"

Store (import data)

mongorestore --uri="mongodb://user:[email protected]:27017/?authSource=admin&directConnection=true" example-dump
mongorestore --uri="<mongodb-uri>" <dump-dir>

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment