How can I display MongoDB queries in the rails console/server
Asked Answered
M

1

2

I trying to use MongoDB with Rails (I never tried MongoDB before). And I want to display the queries made by mongomapper in the rails console or the rails server (like ActiveRecord does)

Is there a way ? Thank you!

Majuscule answered 21/7, 2012 at 16:2 Comment(1)
I know this is not exactly relevant to the question, but if you work with mongodb and rails, take a look at Mongoid instead of MongoMapper. It's times better. mongoid.org/en/mongoid/index.htmlSoaring
S
1

You can turn on logging by passing a logging instance to the ruby driver when creating the connection like this:

MongoMapper.connection = Mongo::Connection.new('localhost', 27017, :logger => Rails.logger)

Documentation for using the logger is here: http://railstips.org/blog/archives/2009/10/09/more-mongomapper-awesomeness/

Though Mongoid is definitely worth taking a look at. It supports logging as well: http://mongoid.org/en/mongoid/docs/installation.html#logging

Stereo answered 23/7, 2012 at 18:59 Comment(1)
The last link regarding mongoid gem is invalid. I clicked on it and it shows "Sorry, we can't find that page. The page might have been moved or deleted."Kiblah

© 2022 - 2024 — McMap. All rights reserved.