Search code examples
mongodbexportmlab

How to export from mlab to local mongoDB


I am new to mongoDB and I need to export the database from mlab to my local mongoDB for development purposes.

I have navigated to my MongoDB\Server\4.0\bin using cmd and tried the commands suggested from mlab:

mongodump -h dsxxxx.mlab.com:xxxxx-d heroku_xxxxxx -u myusername -p mypassword -o datamlab

which gave error: Failed: error dumping metadata: error creating directory for metadata file

I have also tried to replace the 'datamlab' with paths which I don't think works because it says positional arguments not allowed

Since the dump was not working, I also tried to export the data through json by using

mongoexport -h dsxxxx.mlab.com:xxxx-d heroku_2t909tjl -c conversations -u xxxx -p xxxx -o export1.json

which shows the error: error opening output stream: open export1.json: Access is denied.

I have no idea why it is not working...

Please help...


Solution

  • I resolved it by opening command prompt in administrator mode. Also found out that mongodump deletes off the existing entrys from the mlab so I panicked a little but I restored it by doing mongoresotre.

    So basically, I used

    mongoexport -h dsxxxx.mlab.com:xxxx-d heroku_2t909tjl -c conversations -u xxxx -p xxxx -o export1.json

    which exported the specific collection into my bin as "export1.json". Then I just made a new collection in my local mongoDB and named it the same as the collection in mlab and imported "export1.json.

    I also realised you do not need to export and you can just connect directly to mlab from your local mongoDB (which when I tried did not exactly work so I was fine with just exporting the collections)