2015-12-02

MongoDB - Export query to flat file from the command-line

mongo SERVER_NAME_OR_IP:PORT_NUMBER/DATABASE_NAME --eval "var c = db.COLLECTION_NAME.find(); while(c.hasNext()) {printjson(c.next())}" >> TARGET_FILE_NAME.TARGET_FILE_NAME_EXTENSION

Actual example:
mongo localhost:3001/meteor --eval "var c = db.mycoll.find(); while(c.hasNext()) {printjson(c.next())}" >> test.txt

Another example/thread at:
http://stackoverflow.com/questions/12823990/how-to-get-mongo-command-results-in-to-a-flat-file

No comments:

Post a Comment