Recently I was asked to restore a MongoDB database but all I was given was the following URI mongodb://localhost:27017/testdb
I ran mongod and then the following command from within my /usr/local/mongodb/bin folder:
mongorestore --uri "mongodb://localhost:27017/testdb"
After running this command i get the following output:
2019-05-26T23:00:27.148-0400 using default 'dump' directory
2019-05-26T23:00:27.149-0400 preparing collections to restore from
2019-05-26T23:00:27.150-0400 done
However, nothing seems to have happened. This is the first time I do this and I don't know what is happening. I'd really appreciate it if someone could tell me what am I doing wrong. Thank you!
mongorestore --uri mongodb://localhost:27017/dbName --db YOUR_DB_NAME YOUR_TARGET_FOLDER/YOUR_DB_NAME
e.g :
mongorestore '--uri' 'mongodb://localhost:27017/testdb' '--db' 'testdb' '--drop' '../path/mongodump/testdb'
Related
I downloaded an agz file from an open-source site and i want ro restore the db data to my mongodb.
Firstly i execute the command bellow and I got the data successfully.
mongorestore --gzip --archive=filename.agz --db filename
But not all data were restored.There is no space of my disk so that some data failed to be restored. Then I delete some files to get enough space and run that command again.
But this time the command line shows something like duplicate id error. And no new data was added to db.
So I drop the database and run the command bellow:
mongorestore --gzip --archive=filename.agz --nsInclude filename
And after more than 10 mins I got this:
execution result
2022-01-07T11:10:01.015+0800 preparing collections to restore from
2022-01-07T11:22:16.628+0800 0 document(s) restored successfully. 0 document(s) failed to restore.
What happend? Where are my data? How can I solve this problem and get whole correct data from the agz file?
Use nsInclude command
Change code like this and it works:
mongorestore --gzip --archive=filename.agz --nsInclude="*"
as the official site says, --db has been deprecated and you should use --nsInclude instead.
Before restore u`d better ensure there is enough space left in your disk.
I need one help. I need to export and import the total database/all collection for MongoDB using Ubuntu. I am explaining my command below.
sudo mongoexport --db FGDP --out /home/subrajyoti/Downloads/newdbexport.json;
Here i am getting the following error message.
2016-12-22T10:28:46.290+0530 error validating settings: must specify a collection
2016-12-22T10:28:46.290+0530 try 'mongoexport --help' for more information
Here i need to export all collection rather than one single one. Please help me.
Exporting all collections of all database using mongodump use the following command:
mongodump -o <directory_backup>
Your help will be very much appreciated.
We are using mongodb , 3.2.9 version , sharded cluster on RHEL 7.2.
While trying to restore the admin database via mongorestore we get the following error:
restoring users from /home/mongod/admin/system.users.bson
error: Writes to config servers must have batch size of 1, found 11
Indeed there are 11 users in source database.
system.users collection contains 11 documents.
But why would the restore fail ?.. error message is not clear to us.
Restore of other databases was successful.
Same result while trying to restore with and without authentication being enabled.
thanks in advance
You have to use an additional parameter: --batchSize=1 in your mongorestore command.
mongorestore --host <host utl>:<PORT> --db <db name> -u <user name> <path to your local backup> --batchSize=1
tip found here
My mongodb can't lanuch now, when I want start mongo got error ***aborting after invariant() failure
Now I want to restore collection-0-****.wt file to a new db, is this possible?
As at MongoDB 3.2, only full backups of WiredTiger data directories can be copied into a new instance. WiredTiger collection or index files aren't self-contained; they rely on other metadata in the WiredTiger.* catalog files. The invariant/assertion you are getting on startup is expected if data files are incomplete or inconsistent.
If you want to backup and restore a single collection, you should use mongodump and mongorestore, eg:
mongodump --db test --collection northwind --host host1
mongorestore --db test dump/test/northwind.bson --host host2
For supported full backup procedures, see: MongoDB Backup Methods.
I had the same issue and after spending 5 hours doing everything, found this.
https://medium.com/#imunscarred/repairing-mongodb-when-wiredtiger-wt-file-is-corrupted-9405978751b5
You will need to restore 1 collection at a time(a few at once when you get the hang of it), but it works!
It might be a dead simple question yet I still wanted to ask. I've created a Node.js application and deployed it on Heroku. I've also set up the database connection without having any trouble as well.
However, I cannot get the load the local data in my MongoDB to MongoLab I use on heroku. I've searched google and could not find a useful solution so I ended up trying these commands;
mongodump
And:
mongorestore -h mydburl:mydbport -d mydbname -u myusername -p mypassword --db Collect.1
Now when I run the command mongorestore, I received the error;
ERROR: multiple occurrences
Import BSON files into MongoDB.
When I take a look at the DB file for MongoDB I've specified and used during the local development, I see that there are files Collect.0, Collect.1 and Collect.ns. Now I know that my db name is 'Collect' since when I use the shell I always type `use Collect`. So I specified the db as Collect.1 in command line but I still receive the same errors. Should I remove all the other collect files or there is another way around?
You can't use 'mongorestore' against the raw database files. 'mongorestore' is meant to work off of a dump file generated by 'mongodump'. First us 'mongodump' to dump your local database and then use 'mongorestore' to restore that dump file.
If you go to the Tools tab in the MongoLab UI for your database, and click 'Import / Export' you can see an example of each command with the correct params for your database.
Email us at support#mongolab.com if you continue to have trouble.
-will
This can done by two steps.
1.Dump the database
mongodump -d mylocal_db_name -o dump/
2.Restore the database
mongorestore -h xyz.mongolab.com:12345 -d remote_db_name -u username -p password dump/mylocal_db_name/