print from mongo console to file sample.json code example
Example 1: print from mongo console to file sample.json
mongo localhost:27020/miscdb --eval "printjson(db.collection_name.findOne({}))" > sample.json
Example 2: print from mongo console to file
> EDITOR="cat > /tmp/x.json"
> x = db.MyCollection.find(...).toArray()
> edit x
>