Mongodump - command not found when executing dump - mongodb

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>

Related

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

MongoDB replSet exception [duplicate]

The issue seems straight forward. I have a database (test) and a collection called (users) so I run the command:
mongoexport -d test -c users -o output.json
However I get the below error:
As per what I have figured out till now over the internet, this may have something to do with the file path but I am unsure as how to amend this as I never mess with PATH variable due to a bad experience...
You don't run mongoexport from the mongo shell, you have to run it from the OS shell (same as you run mongo)
mongoexport is not a Mongo shell command, it's an operating system command.
Just like you run mongo.exe to start the shell from OS prompt, you should run mongoexport the same way from OS prompt. Example:
c:\mongodb\bin>mongoexport --db ventfeed --collection users --out C:\temp\contacts.json
Thanks

Error when running mongodump

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.

mongorestore syntax error

I have lots of bson files in the following path:
c:/mongodb/bin/dump/Sid
If I run the command:
> mongorestore --db Sid --drop dump/Sid
I get the following error:
Mon Mar 26 14:36:36 SyntaxError: missing ; before statement (shell):1
What is the problem with my command?
From your input, it appears as though you are attempting to run mongorestore from inside the JS shell.
Mongorestore is a standalone application, and is run directly from the terminal.
The following will not work:
c:\mongodb-win32-x86_64-2012-03-20\bin>mongo.exe
MongoDB shell version: 2.1.1-pre-
connecting to: test
> mongorestore --db test --drop \dump\test
Mon Mar 26 11:29:13 SyntaxError: missing ; before statement (shell):1
>
If you run mongorestore directly from the terminal you should be successful:
c:\mongodb-win32-x86_64-2012-03-20\bin>mongorestore --db test --drop \dump\test
connected to: 127.0.0.1
... (truncated for brevity) ...
c:\mongodb-win32-x86_64-2012-03-20\bin>
The documentation on Mongodump / mongorestore may be found in the "Import Export Tools" documentation:
http://www.mongodb.org/display/DOCS/Import+Export+Tools
mongorestore is not a command , it an executable in the bin directory of MongoDB.
Below is the quote from http://docs.mongodb.org/manual/reference/program/mongorestore/
The mongorestore program writes data from a binary database dump
created by mongodump to a MongoDB instance. mongorestore can create a
new database or add data to an existing database.
If you already have a mongod instance running
where you already specified the dbpath as
mongod --dbpath "..\mongodb\data"
you can directly run the mongorestore command .
mongorestore ..\data\dump
You can't use mongorestore command like this...
You have to run this via cmd and not on Mongo Shell... Have a look at below command...
>path\to\mongorestore.exe -d dbname -c collection_name path\to\same\collection.bson
Here path\to\mongorestore.exe is path of mongorestore.exe inside bin folder of mongodb.
dbname is name of databse. collection_name is name of collection.bson.
path/to/same/collection.bson is the path up to that collection.
Now from mongo shell you can verify that database is created or not (If it does not exist, database with same name will be created with collection).
If you want to restore the outside database then copy that database in
<pre>C:\database drive(Create a folder database and copy your database) ,then follow the steps
1)c:\> cd database
2)c:\database>dir
3)c:\database>"\Program Files\MongoDB\Server\3.0\bin\mongorestore.exe"
now open robomongo and check it will contain the restored dbs.. or check on command prompt show dbs</pre>