How to get mongo command results in to a flat file

后端 未结 8 2316
攒了一身酷
攒了一身酷 2021-01-30 06:26

How do I export the results of a MongoDB command to a flat file

For example, If I am to get db.collectionname.find() into a flat file.

I tried

8条回答
  •  忘了有多久
    2021-01-30 07:09

    Having missed the db needing to be the actual db in Peshkira's answer, here is a general syntax for a one liner in shell (assuming no password):

    mongo : --eval "var x = ..; while(x.hasNext()) { printjson( x.next() ) }" >> out.txt
    

    I tested it both on my mac and Google cloud Ubuntu 15 with Mongo 3+.

提交回复
热议问题