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

前端 未结 10 1936
余生分开走
余生分开走 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:21

    Just put the commands you want to run into a file, then pass it to the shell along with the database name and redirect the output to a file. So, if your find command is in find.js and your database is foo, it would look like this:

    ./mongo foo find.js >> out.json
    

提交回复
热议问题