I need to migrate a Mongo database from one server to another server.
Eu preciso migrar um banco de dados Mongo de um servidor para outro servidor.
And now, what to do?
E agora, o que fazer?
The following 5 simple steps to get it done.
Segue 5 passos simples para que isso seja feito.
In this case , MongoDB was running on Windows.
Neste caso, o MongoDB estava rodando em Windows.
1) Open the terminal and go to the bin directory of your mongo and start mongodb server:
Abra o terminal e acesse o diretório bin do seu mongo e inicie o servidor do mongodb:
cd C:\Program Files\MongoDB\Server\3.2\bin C:\Program Files\MongoDB\Server\3.2\bin> mongod
2) If you have not backup , do:
Caso não tenha o backup, faça um:
cd C:\Program Files\MongoDB\Server\3.2\bin C:\Program Files\MongoDB\Server\3.2\bin> mongodump --db test --out c:\data\db
Note: it is recommended that be with the bank that will be backed up off.
Obs: é recomendado que esteja com o banco que será feito o backup off.
3) Create the database you want, on the destination server , and log out of the base:
Crie o banco que deseja, no servidor de destino, e deslogue do banco:
cd C:\Program Files\MongoDB\Server\3.2\bin C:\Program Files\MongoDB\Server\3.2\bin> mongo
For create a new database:
Para criar um novo db:
use testnew exit
4) Copy the files generated by the dump ( the source server ) to the destination server, and then restore the source database in the new database that was created on the target server :
Copie os arquivos gerado pelo dump (servidor de origem) para o servidor de destino, e depois restaure o banco de origem no novo banco que foi criado no servidor de destino:
cd C:\Program Files\MongoDB\Server\3.2\bin C:\Program Files\MongoDB\Server\3.2\bin> mongorestore --db testnew c:\data\db\test
5) Ready ! Now go to the testnew instance and check their collections:
Pronto! Agora acesse a instância testnew e confira as suas coleções:
cd C:\Program Files\MongoDB\Server\3.2\bin C:\Program Files\MongoDB\Server\3.2\bin> mongo use testnew show dbs show collections