Is there a way to 'pretty' print MongoDB shell output to a file?

前端 未结 10 1942
余生分开走
余生分开走 2020-11-27 09:38

Specifically, I want to print the results of a mongodb find() to a file. The JSON object is too large so I\'m unable to view the entire object with the shell wi

10条回答
  •  温柔的废话
    2020-11-27 10:22

    As answer by Neodan mongoexport is quite useful with -q option for query. It also convert ObjectId to standard format of JSON "$oid". E.g:

    mongoexport -d yourdb -c yourcol --jsonArray --pretty -q '{"field": "filter value"}' -o output.json
    

提交回复
热议问题