spool output from mongodb shell

2,185 views
Skip to first unread message

THOL

unread,
Nov 17, 2011, 6:55:01 PM11/17/11
to mongodb-user
Hi,

Is there a way to spool output to a file when working in mongodb
shell? Similar to spool command in sqlplus.

Thanks
Thol

Tyler Brock

unread,
Nov 17, 2011, 7:10:44 PM11/17/11
to mongodb-user
You can always redirect the output to a file by using ">"

Example:
mongo commands.js > output.txt

If you use print statements whatever you would normally see during the
session will be written to the file.

Does that help?

-Tyler

Tyler Brock

unread,
Nov 17, 2011, 7:24:22 PM11/17/11
to mongodb-user
You might also want to take a peek at this documentation:

http://www.mongodb.org/display/DOCS/Scripting+the+shell

THOL

unread,
Nov 18, 2011, 12:00:58 AM11/18/11
to mongodb-user
Thank you for the reply. I wanted to have formatted JSON output saved
in a file just as you query the database. That can be later used for
reference.
I guess printjson() is a good alternative but it has to be run as a
script.

Thanks
Thol

Crazybaby

unread,
Nov 18, 2011, 1:18:53 AM11/18/11
to mongodb-user
you can use mongoexport of Mongo Tools . export json and scv fmt;
Reply all
Reply to author
Forward
0 new messages