save query results in a text file?

7,721 views
Skip to first unread message

Aleksei T

unread,
May 15, 2011, 6:52:21 PM5/15/11
to mongod...@googlegroups.com
I guess its one of those days, can't seem to find an easy answer to a question.  If I need to output query results from MongoDB to a flat file (to use in excel or whatever), what would I use?  mongodump doesn't seem like the right tool (or does it?) - I think it outputs bson data, not text-viewable. 

Aleksei T

unread,
May 15, 2011, 6:53:38 PM5/15/11
to mongod...@googlegroups.com
and I guess it's mongoexport :)  false alarm, thanks!!

shashank sharma

unread,
Nov 18, 2013, 4:06:54 AM11/18/13
to mongod...@googlegroups.com
Group by queries create problem with mongoexport,......mongoexport can done only simple queries...i am still trying to find another way

James Tan

unread,
Dec 30, 2013, 6:10:26 AM12/30/13
to mongod...@googlegroups.com
There are many ways to do this, the easiest probably being a one-liner like the following in the terminal:

  mongo --quiet --eval "cursor = db.test.find(); printjson(cursor.toArray())" > output.txt

Which will output the contents of the "test" collection in the "test" database, in JSON format to the file output.txt.

Regis Maicon

unread,
Jan 4, 2016, 5:00:28 PM1/4/16
to mongodb-user
Thanks! :)
Reply all
Reply to author
Forward
0 new messages