Is there a way to write the output of a MongoDB find() query to a file just by simply using a Linux shell command or running a script?
Right now I have to manually type in step-by-step. Example:
$ mongo
> use owndb
> db.CollectionName.find(<query>) ### and then copy and paste the result on a text editor
You may try this:
mongo --quiet dbname --eval 'printjson(db.collection.find().toArray())' > output.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With