mongodb database don't export from mLab cloud - mongodb

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.

Related

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.

MongoDB shell find query

I am running a simple find query from unix shell.
mongo <<DB NAME>> -u <<USERNAME>> -p <<PASSWORD>> <<HOST>>:<<PORT>> --authenticationDatabase <<AUTHENTICATION DB NAME>> --eval db[<<COLLECTION NAME>>].find({"name":"Harsha"})
I am getting below error.
[js] SyntaxError: missing ; before statement #(shell):1:6
I also tried by changing DB name place (ex: host:port/db_name)
mongo -u <<USERNAME>> -p <<PASSWORD>> <<HOST>>:<<PORT>>/<<DB NAME>> --authenticationDatabase <<AUTHENTICATION DB NAME>> --eval db[<<COLLECTION NAME>>].find({"name":"Harsha"})
Still getting same error.
Am I missing something? Can anyone please help?
MongoDB expects the argument of --eval to be passed as string like in this example:
--eval "db[<<COLLECTION NAME>>].find({'name':'Harsha'})"

getting error while exporting mongodb using mongo cmd in windows

I am trying to export mongodb database using this command:
mongoexport -d db_name
But I am getting this error:
SyntaxError: missing ; before statement #(shell):1:15
What will be the command to export db?
You can use mongodump it's faster:
mongodump -d <database_name> -o <directory_backup>
And to restore/import that, i used (from directory_backup/dump/):
mongorestore -d <database_name> <directory_backup>

MongoDb throws an error while importing using mongoImport

Dear MongoDb experts,
So I have an assignment of which the first step is to import a java script file called Grades. I have the file stored in IPD351 folder in my C drive. I am running the following command in my command prompt after connecting to the mongo db server:
MongoDB Enterprise > mongoimport -d students -c grades <C:\foldername\filename.js
But I get the following error:
2016-04-18T13:35:04.983-0500 E QUERY [thread1] SyntaxError: missing ; before statement #(shell):1:15
Please help! If the file does not get imported I cannot do the remaining homework
RESOLVED! I was in the mongo enterprise, typed exit, got out of enterprise and then typed the import command and it worked! The new line looks like this:
C:\Users\Akhil\mongoDb> mongoimport -d students -c grades
Don't use the < just ype the file path:
mongoimport -d students -c grades C:\IPD351\grades.js

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>