Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongorestore from standalone to replicaset

Tags:

mongodb

I have dumped a standalone mongo database (14Gb big) running on the default port as follows:

mongodump --username <username> --password <password> --db <dbname>

and I am trying to restore it onto a replica set with the following:

mongorestore --host myReplSet/127.0.0.1:27020 --drop --username <username> --password <password>

The restore seems to work (it takes a minute or so and the output looks good) the database is created and all the collections are created but there is no data in the collections, they are all empty. What am I doing wrong?

For what it is worth, the local database is showing that it is 10 Gb big (I am not sure how big it was before the restore)

like image 839
Clinton Bosch Avatar asked Oct 02 '22 12:10

Clinton Bosch


1 Answers

If anybody is facing the same issue. I used a replica set, and tried to do the Op's command. i.e

mongorestore --host myReplSet/mongo0.example.com:27020,mongo1.example.com:27012 --db <dbname> <folder_location>

Instead just go to the primary server and do this

mongorestore --port <if running on port other than 27017> --db <dbname> <location of dump>

This works for me, A possible explanation could be that whenever I write into the primary database, it is automatically copied over to my secondary databases. Hence no need to give any replica set address. This might work if you write in a secondary, I am not sure, haven't tried it. Maybe somebody else can throw a light on it.

like image 86
Saras Arya Avatar answered Oct 12 '22 10:10

Saras Arya