Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to Use Mongo Export Query

Tags:

mongodb

I have a collecton named "sample" and database named "at" present in Mongo DB .

db.sample.find().pretty()
{
        "_id" : "35004",
        "city" : "ACMAR",
        "pop" : 6055,
        "state" : "AL"
}
{
        "_id" : "35005",
        "city" : "ADAMSVILLE",
        "pop" : 10616,
        "state" : "AL"
}
{
        "_id" : "35006",
        "city" : "ADGER",
        "pop" : 3205,
        "state" : "AL"
}

I have tried using mongo export query , but i was unsuccessful , please let me know where i am doing mistake .

I have tried using below ways , but always produced an error .

mongoexport --host localhost --db at --collection "sample" --csv --out text.csv --fields city,state

mongoexport --csv -o /D:/test.csv -d at -c sample -f city,state,pop

I was getting the following error , please help

Sun Mar 10 00:25:44 SyntaxError: missing ; before statement (shell):1

like image 645
Pawan Avatar asked Mar 09 '13 18:03

Pawan


People also ask

How do I export MongoDB query results to JSON?

Format Option: Choose JSON-mongo shell/ JSON-mongoexport. Target: Choose between clipboard/file & make sure the file path is defined. Others: Choose whether to export with commas between documents or export as a document array. Output Preview: Displays the final JSON document.


1 Answers

mongoexport must be run from your OS command shell, not the mongo shell.

like image 103
JohnnyHK Avatar answered Nov 27 '22 18:11

JohnnyHK