Zac*_*Zac 3 mongodb mongodb-query
有没有一种方法可以仅通过使用 Linux shell 命令或运行脚本将 MongoDB find() 查询的输出写入文件?
现在我必须一步一步地手动输入。例子:
$ mongo
> use owndb
> db.CollectionName.find(<query>) ### and then copy and paste the result on a text editor
你可以试试这个:
mongo --quiet dbname  --eval 'printjson(db.collection.find().toArray())' > output.json
您可以使用mongoexport来实现这一点。
例子:
mongoexport -d dbname -c collection --jsonArray --pretty --quiet --out output.json
| 归档时间: | 
 | 
| 查看次数: | 9200 次 | 
| 最近记录: |