Error when running mongodump - mongodb

I have a rollback file, but when I run mongodump on it I get an error:
mongodump.exe .\test.foo.2016-04-27T16-49-54.0.bson > f.json
02:33.521+0100 positional arguments not allowed: [.\test.foo.2016-04-27T16-49-54.0.bson]
02:33.522+0100 try 'mongodump --help' for more information

You just used the wrong command. You have to use the bsondump command instead of the mongodump command. Mongodump is only for create of the backup file. From the parameters you provide in your command I assume that you want to convert the bson file to a human-readable json file.

Related

Mongodump - command not found when executing dump

I'm trying to create a backup of my database using Mongodump. The problem is that every time i execute the dump, i get the following error:
--collection: command not found
Here is the command:
mongodump --uri=MYURI --collection TEST-COL --gzip --out=/var/backups/testbackup
I'm using linux, while on windows the same command seems to work. Any advice?
The URI is a connection string, must be wrap with double quotes ("").
--uri=<connectionString>

How to restore a db in mongoDB

i tried to restore a db using mongorestore but i get this error:
2020-09-14T18:48:59.210+0200 error parsing command line options: error parsing positional arguments: provide only one polling interval in seconds and only one MongoDB connection string. Connection strings must begin with mongodb:// or mongodb+srv:// schemes
2020-09-14T18:48:59.258+0200 try 'mongorestore --help' for more information
I tried a lot of combinations, like this:
mongorestore -h localhost -d projectdb C:\Users\leo\Downloads\project\projectdbfiles
But without success.. i read the documentation and i tried to use --host:host and /host:host..
Im using windows
Below solution worked for me
Copy mongorestore.exe to C:\Users\leo\Downloads\project folder
open command prompt C:\Users\leo\Downloads\project\ location
mongoservice.exe projectdbfiles\
it should work.

Cannot mongodump to a single archive

I'm trying to dump a MongoDB database to an archive. Using the following command as given in documentation.
sudo mongodump --uri=mongodb://username:password#host:27017/dbname?authMechanism=SCRAM-SHA-1&authSource=authdb --archive=file.archive
But it doesn't dump as expected rather it creates a dump folder with .json file for each collection, which should be a single archive file as given.
It also shows the following error -
--archive=file.archive: command not found
Mongo version -
MongoDB shell version v3.6.3
I had this problem & I figured out the reason it was happening.
The command I was running was
sudo /usr/bin/mongodump --uri=mongodb+srv://{username}:{password}#{atlasendpoint}.mongodb.net/?retryWrites=true&w=majority --archive={filename}.archive --gzip 2>&1
I was getting the same error as you. I change the shell command by wrapping quotation marks around the URL; this fixed it for me.
sudo /usr/bin/mongodump --uri="mongodb+srv://{username}:{password}#{atlasendpoint}.mongodb.net/?retryWrites=true&w=majority" --archive={filename}.archive --gzip 2>&1

mongodump fail: error creating bson file, no such file or directory

Trying to backup my data base.
My mongoDB version is: 3.0.12
I am getting this error:
$ mongodump --out .
2017-05-19T09:45:29.536+0000 Failed: error creating bson file `city/address_/house_sensors:power_sensors.bson`: open city/address_/house_sensors:power_sensors.bson: no such file or directory
Is it because I used slash character in my collection name?
How can I fixe that?
Thanks!
As you pointed, the problem is with your collection name. I'd recommend to rename it to something without slashes.
If you cannot rename it (it's used by other systems) you should use the output option with "-" so it is written to standard output, then redirect it to a file:
mongodump -d yourDB -c "your/colName" --out "-" --quiet > col.bson
Then you can restore it with:
mongorestore -d yourDB -c "your/colName" col.bson

Inserting JSON document into mongo error

I'm trying to insert the TWDS1E1.json file into mongodb through the command prompt:
db.collections.insert( TWDS1E1.json )
But getting the error:
TWDS1E1.json is not defined.
Mongo is not my thing, what am I doing wrong here?
In command prompt whose directory path is the path where mongoimport.exe is available type the commands
For normal JSON
mongoimport -d test -c docs --file example2.json
For array type JSON
mongoimport --jsonArray -d test -c docs --file example2.json
Please see docs for more information
You cannot use the collection.insert() command to insert a file.
insert() is used to insert actual objects, e.g.
db.myCollection.insert({"name":"buzz"});
To bulk load a JSON file, use mongoimport