Error regarding the execution of mongoexport - mongodb

When I'm typing mongoexport in my mongoshell, it is showing the following error,
mongoexport
Fri Nov 22 10:07:18.614 ReferenceError: mongoexport is not defined.
Please help me in this issue?

This is for windows machine
mongoexport must be run from your OS command shell, not the mongo shell.
Go to command prompt : ( cd C:\Program Files\MongoDB\Server\3.4\bin ) for x64 machine
mongoexport --help

Related

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

mongodb database don't export from mLab cloud

I have try to export my old mongodb database from mLab cloud, but it's show an SyntaxError. Please see my query and SyntaxError below :
query: mongoexport -h ds02575.mlab.com:25752 -d heroku_g2dn9rd9 -c accounts -u adam -p dino -file accounts.json
And SyntaxError: 2017-12-28T10:36:37.340+0600 E QUERY [thread1] SyntaxError: missing ; before statement #(shell):1:15
Please tell me how can i export it, It's really important for me now
Thanks
Mongoexport should be run from the system command line, not from the mongo shell.

Calling mongoimport from a script

I am trying to run a script from windows powershell:
.\mongo.exe localhost:27017/test --quiet test.js
that calls mongoimport:
var c_env = 'dev';
if (c_env === "dev")
{
./mongoimport.exe -d noeldb -c order_notifications --file "D:\Utilities\mongodb\bin\mycollection.json";
}
I get the following error:
Tue May 29 09:47:00 SyntaxError: syntax error D:\Noel\Temp\test.js:5
failed to load: D:\Noel\Temp\test.js
Is it possible to do this?
When you run a JS script file the commands inside of it will be executed from the mongo shell.
You are doing the equivalent of:
C:\> mongo.exe
MongoDB shell
connecting to test
> ./mongoimport.exe ...
This will not work because mongo shell is expecting mongo syntax (Javascript) not Windows/powershell commands.
If you want to invoke mongoimport.exe from a script the simplest way would be to do it from a DOS/powershell script.

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>