ruby-on-railsmongodbmongoidmongomapper

from the rails console, how can I query a mongo collection with human readable output?


from the rails console, how can I easily query a mongo collection with nice tab style output in a human readable form:

Person.all.each { |p| pp p }

that will return a mess of each document printed one after the other, but none of the cols are lined up.


Solution

  • AFAIK you have a couple options:

    1. Be content without columns and use pp or the very pretty awesome_print. With awesome_print I often do: ap Person.all.map(&:to_mongo) The to_mongo method will produce nicer output than pp'ing or ap'ing the object itself.

    2. Roll your own. Check out terminal-table as a place to start.