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!

Mathieu Mahé
  • 2,647
  • 3
  • 35
  • 50
  • 2
    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. http://mongoid.org/en/mongoid/index.html – Moox Jul 21 '12 at 17:27

1 Answers1

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

Emily S
  • 369
  • 1
  • 4
  • 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." – Victor Aug 24 '23 at 15:17