Skip to content

Instantly share code, notes, and snippets.

@GregIngelmo
Last active December 17, 2015 03:28
Show Gist options
  • Save GregIngelmo/5542927 to your computer and use it in GitHub Desktop.
Save GregIngelmo/5542927 to your computer and use it in GitHub Desktop.
Interactive Mongo queries
# Launch pry based interactive Rails console
$> pry -r ./config/environment.rb
# redirect Mongoid logging to console
pry(main)> Mongoid.logger = Logger.new($stdout)
# run a query
pry(main)> User.where(:username => "greg").first()
# Mongoid spits out the query, but, I actually want to see the raw Mongo query
MONGODB (515.5ms) development['users'].find({:username=>"greg"}).limit(-1).sort([[:_id, :asc]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment