MongoDB replSet exception [duplicate] - mongodb

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

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>

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

Syntax missing ; before statement in mongoexport

I am trying to export mongodb collection with:
mongoexport -d InventoryPLC -c Spectra -o spectra.json;
but it is giving me error:
Syntax missing ; before statement
I search on mongodb website and other reference websites:
mongoexport -d InventoryPLC -c Spectra;
I want to export collection.
I checked stackoverflow examples and mongodb documentation:
mongoexport -d InventoryPLC -c Spectra -o spectra.json;
I want exported collection, but have had no luck.
Appreciate the help.
You are probably trying to run mongoexport from inside the Mongo shell. That command must be executed outside it, from your OS command shell.

Cannot import mongodb

I tried mongo import like this
mongoimport -d test -c foo importfile.json
mongoimport --host localhost --db local --collection lecturer --type json --file temp.json --headerline --upsert
and I've got same error message "Syntax Error: missing ; before statement (shell):1"
what's wrong with my code & how to import if my data stored in C:\Documents and Settings\User\Desktop ?? please help, thank's in advance
mongoimport is intended to run in command prompt and not in the mongo shell. Try exiting out of the shell and running the command.
One solution is:
First, in cmd, change to the directory containing mongoexport.exe file, then type your command.
C:\Program Files\MongoDB\Server\3.2\bin> .\mongoexport.exe -d foo -c bar -o output.json
mongoimport is to be run on the terminal and not inside the mongo shell. To run mongoimport in terminal, you will need to install the same. On ubuntu, you can do :
apt-get install mongo-tools
Hope this helps :)
I had the same problem and was able to figure it out after a brief struggling and googling.
1. Navigate to the bin directory in command prompt
(cd c:..\bin)
2. Run the mongoimport command but you have to specify the full path of your json file.
That solves the problem
try to use CSV is a good.
mongoimport -d mydb -c things --type csv --file locations.csv --headerline --upsert
You can convert by ms excel.
Open the "Mongo/Server/3.4/bin" folder of mongo db in another command window and try again.It Will work.
Open a new terminal or command prompt within the location of the file you want to import and it should work. It will not work on MongoDB shell

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>