Skip to content

Instantly share code, notes, and snippets.

@iambryancs
Last active July 5, 2023 12:26
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 iambryancs/1a77c0ebf219489b8a8ad72b4054c753 to your computer and use it in GitHub Desktop.
Save iambryancs/1a77c0ebf219489b8a8ad72b4054c753 to your computer and use it in GitHub Desktop.
MongoDB dump and restore using mongodump and mongorestore.
#!/bin/bash
SRC_DB_URI='mongodb+srv://username:password@src_host/'
SRC_DB_NAME=src_db_name
DEST_DB_URI='mongodb+srv://username:password@dest_host/'
#not probably needed as well as the `--db` under `mongorestore`
DEST_DB_NAME=dest_db_name
mongodump \
--archive \
--uri=$SRC_DB_URI \
--db=$SRC_DB_NAME \
--port=27017 | \
mongorestore \
--archive \
--nsInclude="*" \
--nsFrom="src_db_name.*" \
--nsTo="dest_db_name.*" \
--uri=$DEST_DB_URI \
--db=$DEST_DB_NAME \
--port=27017 -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment