Skip to content

Instantly share code, notes, and snippets.

@skounis
Created February 28, 2022 11:33
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 skounis/93bf1f370541d1d1c19b5d24916b40ad to your computer and use it in GitHub Desktop.
Save skounis/93bf1f370541d1d1c19b5d24916b40ad to your computer and use it in GitHub Desktop.
Migrate MongoDB with mongodump and mongorestore

Dump the existing

mongodump -h 127.0.0.1:27017 -u "DB_USER" -p "PASSWORD" --db DB_NAME --archive=$HOME/backup/dump.gz --gzip

Restore

As a root user, no auth.

mongorestore --host=127.0.0.1 --gzip --archive=dump.gz

Create user in the new DB Engine

Selecte the DB_NAME

db.createUser(
    {
        user: "DB_USER",
        pwd: "PASSWORD",
        roles: [
            { role: "readWrite", db: "DB_NAME" }
        ]
    }
)

References

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