0

I would like to know how to output a large document using something like unix's more command in a Mongo shell.

I have a large document that I want to inspect, but it quickly fills my terminals maximum height. As a result I cannot see the beginning part of it. Any suggestions?

mc9
  • 6,121
  • 13
  • 49
  • 87
  • I don't think thats is possible in MongoDB. You can export your data into file by `mongoexport`. Or, you can try MongoDB `projection` Or, via JS, create script and split data into small pieces. The better way is use MongoDB GUI, like Robomongo which is fantastic for working... – Valijon Jan 03 '16 at 23:22

1 Answers1

0

Actually, that is pretty easy and there is no need for a GUI:

mongo  --eval 'db = db.getSiblingDB("yourdb");
  c = db.yourCollection.find({"answer":42},{"_id":0,"question":1});
  while(c.hasNext()){
    printjson(c.next())
  }' | less

(Indented for readability, works nevertheless)

Markus W Mahlberg
  • 19,711
  • 6
  • 65
  • 89