Mongorestore don't know what to do with file "db/collection.bson", skipping - mongodb

I want to migrate my mongodb from 2.0 to 3.0. So I followed the official doc to use mongodump to backup my dbs and use mongorestore to restore the dbs to mongodb 3.0.
But when I use mongorestore, it tells me "don't know what to do with file "db/collection.bson", skipping...".
Nothing to do. How could I migrate my dbs?
Thanks.
EDIT: Here is my steps.
Use mongodump in mongodb 2.0
mongodump
tree dump
db
├── collection-1.bson
├── collection-2.bson
├── collection-3.bson
├── ...
Copy db directory to mongodb 3.0 server.
On the mongodb 3.0 server calls mongorestore db
But I get this error:
mongorestore db
2015-03-10T09:36:26.237+0800 building a list of dbs and collections to restore from db dir
2015-03-10T09:36:26.237+0800 don't know what to do with file "db/collection-1.bson", skipping...
2015-03-10T09:36:26.237+0800 don't know what to do with file "db/collection-2.bson", skipping...
2015-03-10T09:36:26.237+0800 don't know what to do with file "db/collection-3.bson", skipping...
...
2015-03-10T09:36:26.237+0800 done

It seems one must also specify -d in 3.0 like this:
mongorestore -d db db

This answer isn't directly related to your issue case, but the same error output you will receive trying to restore mongo data, dumped with --archive option, available since MongoDB 3.2 version. To resolve this you need to specify --gzip parameter in your mongorestore command. Example:
mongorestore -d destination_db --gzip /path/to/source/db

If you have lost your mongoDb just try running this command:
mongorestore -d destination-db --gzip source-db
Where:
destination-db is the name of the destination database
source-db is the name of the source database.

Following command worked for me in mongoDB 6.0 -
mongorestore --host localhost --port 27017 --db DB-NAME DB-BACKUP-PATH
Please replace DB-NAME and DB-BACKUP-PATH with your actual values. For ex.
mongorestore --host localhost --port 27017 --db demo_db /home/ubuntu/db-backup
Where "/home/ubuntu/db-backup" contains all collections in bson and json format.

Try this one.
mongorestore -db dataBaseName dataBasePath

In order to import data to your mongodb ,You need to specify --db configuration in mongorestore function with name and path, this works for me for bson and json files as well:
mongorestore --db <dbName> <dbPath>
check the data was imported properly using mongo cli
mongo
show databases
use <dbName>
show collections

With mongorestore, the path of those dump files is a required parameter; you've got that right so far, by indicating db.
It is also a good idea as Peter has said to indicate a database to restore the dump files into collections with a /d switch.
Something I didn't realize while struggling with this is that a mongod must be running to consume the restoration. If you have more than 1 mongod running, you should definitely indicate a port with the --port switch. The code that worked for me was:
mongod --dbpath config --port 27019 --logpath log.config --logappend
And in another CLI:
mongorestore --port 27019 /d config config
followed by
mongo localhost:27019/config
to verify that the collections were filled properly.

You want to run mongorestore on the dump directory, not the db/ directory.
mongorestore dump/

Please Follow these intstructions it worked for me
First go to command prompt .
run cd C:\Program Files\MongoDB\Server\3.0\bin .
now ,For suppose your data is in a folder called trading and it contains json files .
and the path for that might be c:\Users\documents\trading.
(mongorestore -d dbName dbPath).
now run mongorestore -d trading c:\Users\documents\trading.
your files will be restored.

Not directly related to your situation but someone could stumble upon this post with similar error for this reason
In my case, the data was provided to me and had been dumped using
mongodump --db ${DB_NAME} --gzip -o ${BACKUP_FILE_GZ}
To restore, you must use following format:
mongorestore --gzip --db "${DB_NAME_RESTORE}" ${BACKUP_FILE_GZ}/${DB_NAME}

mongorestore --uri "mongodb+srv://<user>:<password>#<host>" -d <dbname> <dump dir. address ./something/like/this>
This work fine for me

I used docker to start my mongo db instance & I had default username and password
auth set for database.
Below is how my restore looked like.
mongorestore --authenticationDatabase admin -u root -p example -d test-db /data/test-db
So in-short something of this sort should work.
mongorestore --authenticationDatabase admin -u {USERNAME} -p {PASSWORD} -d {DB_NAME} {/DUMP_PATH}

Related

How to restore dump backup in mongodb

I have restore-63bbdc996664dc2524cce24d.tar file, I am restoring it in the MongoDB database
tried these commands
mongodump --db test --gzip --archive=restore-63bbdc996664dc2524cce24d.tar
mongodump --db test --archive=restore-63bbdc996664dc2524cce24d.tar
mongodump --host localhost --port 27017 --db test --gzip --archive=restore-63bbdc996664dc2524cce24d.tar
mongorestore --drop C:\Users\rustam\restore-63bbdc996664dc2524cce24d.tar.gz -v
error => Failed: file C:\Users\rustam\restore-63bbdc996664dc2524cce24d.tar.gz does not have
.bson extension
I also tried to convert this file to bson by the command
bsondump --outFile=C:\Users\rustam\restore-63bbdc996664dc2524cce24d.tar.gz coll.bson
Can anyone please tell me what should I do to restore the database?
Thanks in advance for any comment or answer.
Extract the archive file using tar -xvf restore-63bbdc996664dc2524cce24d.tar
Use mongorestore --db test --drop <path/to/extracted/bson/files> to restore the dump.
Keep in mind that this command will drop any existing collections in that database before restoring, so make sure you have taken necessary backups.
After spending a lot of time on it finally I got the solution
1. Extract the tar file
2. Run the below command
mongod --port your_port --dbpath your_extracted_tar_folder
note: port is optional, it will run 27027 default port
3. Go and connect on the same port that you pass

MongoRestore is giving me the system cannot find the file

I am trying to export my local mongodb data to an atlas cluster and i created a dump and now i am using the command,
mongorestore --host Cluster0-shard-0/cluster0-shard-00-00-qwo7v.mongodb.net:27017,cluster0-shard-00-01-qwo7v.mongodb.net:27017,cluster0-shard-00-02-qwo7v.mongodb.net:27017 --ssl --username username --password <PASSWORD> --authenticationDatabase admin
to try to restore it but is giving me the system cannot find the file specified.
But if i type mongorestore then it works but it doesn't restore to the atlas cloud server whatever.
What am i doing wrong?
Edit: The path i have used is C:\Program Files\MongoDB\Server\4.2\bin\dump\gfg and dump\gfg but it is still not working.
Usage of MongoRestore.exe can be found here.
Standalone MongoDB
When you use mongorestore, you need to provide the location of the file/dump you need to restore
mongorestore --host=mongodb1.example.net --port=27017 --username=user --authenticationDatabase=admin /opt/backup/mongodump-2011-10-24
last portion of the command is missing that defines the location of the data that needs to be restored.
ReplicaSet
To Restore MongoDB on a Replica, You have to stop the mongod and replace the files for mongodb. Please read here for restoring database on replica set.
For restore from standalone to replica,
mongorestore --host myReplSet/mongo0.example.com:27020,mongo1.example.com:27012 --db <dbname> <folder_location>
If this still does not work, check path and ensure its properly escaped (spaces in name) or quoted.
Your code with quotes and path:
mongorestore --host Cluster0-shard-0/cluster0-shard-00-00-qwo7v.mongodb.net:27017,cluster0-shard-00-01-qwo7v.mongodb.net:27017,cluster0-shard-00-02-qwo7v.mongodb.net:27017 --ssl --username username --password <PASSWORD> --authenticationDatabase admin "C:\Program Files\MongoDB\Server\4.2\bin\dump\gfg"

Mongodump doesn't work as expected

I am trying to host my database online and based on what I have found online, I need to use mongodump to export my database first.
The way to use mongodump if am not wrong is:
mongodump -d <db-name> -o <directory>
when I use the above command, I get the following error in the terminal:
Failed: error connecting to db server: no reachable servers
I tried to add --host=127.0.0.1 after mongodump as follows:
mongodump --host=127.0.0.1 -d <db-name> -o <directory>
But I still get the same result. What am I doing wrong here?
Update:
I managed to overcome the error by starting the MongoDB service with the following command:
brew services start mongodb
Now when I run mongodump, it seems to be working but I can't find it when I navigate to the directory where it supposed to be located!
NOTE: I am using Meteor technology, and I am accessing my database with meteor mongo command
If you are doing mongodump from a remote server it can happen that versions are incompatible. This results in no documents being dump without any warnings. (At least from my tests, mongodump 2.6.10 won't be able to dump from mongod 3.2.13)
Also, make sure bash special characters are not breaking up your query.
Example:
mongodump --db DB_name --collection colname --query "{$or: [something1, something]}"
The previous query won't work as you need to escape the $ with \.
mongodump --db DB_name --collection colname --query "{\$or: [something1, something]}"
You could try:
Run mongodump --db <database> --port 3001 from the directory you want the output files to be created (it will create a dump dir with the files)
The port is 3001, as it seems meteor doesn't use Mongodb default port
Also, if nothing appears, try running with the -v flag for verbose mode, this will help you to find out why your files are not being created. Also, be sure yout database name is correct.

Mongodb's "mongodump" command, javascript execution error

Perhaps I have a complete misunderstanding of how mongodump is supposed to work, but I can't seem to get it to do anything besides returning a JavaScript execution failed: SyntaxError: Unexpected identifier error.
Here's what I'm doing:
Mongod is running
I want to backup a database called "mydb"
I'm inside the mongo shell
I tried the command mongodump --db mydb and get the above error
I've tried both mongodump and mongoexport, both have the same issue
What am I doing wrong here?
Try the following it will work
i.Open the terminal
ii. Enter mongodump --collection collectionname --db dbname (Don't go inside mongo shell);
iii.If default port is different(other than 27017) then go for the following command
mongodump --host mongodb1.example.net --port 37017 --username user --password pass --out /opt/backup/mongodump-2011-10-24
mongodump,mongorestore is not commands of mongodb shell. It is separate mongodb utlity. You can find it under mongodb bin folder.
Usually you will need to add all mongodb utilities to the system Path variable and after this easy backup/restore databases from any place in the command line or in the terminal.
Your command looks mongodump --db mydb good if your databases in on default port(27017).
I faced the problem in taking mongo dump and I also wanted to store the dump to S3. Finally I ended up with a bash script to take mongo dump and store it to S3. I used mongodump to take backup.
mongodump -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE
Where $MONGO_HOST,$MONGO_PORT and $MONGO_DATABASE are bash variables for host, port and database-name respectively.
You can also use --username user --password pass option for mongodump command if you have username and password setup on the database.
Here is the script to take mongodb dump and store it to S3 with a cron.

How to use backup and restore all databases from mongodb?

If i want to do a generic backup for all databases in mongodb, is it that all i have to do is:
$ mongodump
And if i want to restore the latest dump i've created, all i need to do is:
$ mongorestore
Where are the backups from the mongodump stored?
How to i specify a specific dump for all databases to be restored?
The backups are stored in the directory that you have specified with the --out option in command line. If you do not specify any output dir the backup will be placed to ./dump directory. With the mongorestore you have to specify the directory where you have dumped before as a command line argument.
On sharded environment the backup will be flattened if you use mongodump through a mongos. After restore you will have to re-shard the collections. so restoring not always effortless. See documentation:
http://docs.mongodb.org/manual/tutorial/backup-small-sharded-cluster-with-mongodump/
You can dump directly the db folders too, check the cli options.
For sharded clusters you can check the possibilities here: http://docs.mongodb.org/manual/administration/backups/#sharded-cluster-backups
restore all
mongorestore --host= --port= --username= --authenticationDatabase= --nsInclude "."
backup all
mongodump --ssl --host --port -p --authenticationDatabase -u -p --out
If you want to backup databases use:
mongodump --ssl --host --port -p --authenticationDatabase -u -p --out
if the database has ssl enabled include the --ssl flag
if you don't include the --out mongodump will create a "/dump" directory.
inside the dump or specified backup directory you'll find directories with the names of your databases, inside each of them, you'll find the backups files, for each collection you'll find a ".bson" and a ".metadata.json"
To restore all the databases use:
mongorestore --ssl --host= --port= --username= --authenticationDatabase= --nsInclude "."
Again if the database has ssl enabled include the --ssl flag if not just remove it.
the "--nsInclude" flag tell mongorestore which databases or collections you want to restore.
Examples:
--nsInclude=test.users (this will backup the users collection of the database test, and therefore will fail if the path to the dump is anything but the path to the users.bson of that particula database)
To include all the database and all the collections use --nsInclude=. or --nsInclude .
then define the path to all the collection directories of your backup