ruby-on-railsruby-on-rails-3mongodbmongomapper

MongoMapper Console Messages


I am running Rails with the MongoMapper plugin. In dev mode my console is being flooded with messages for each MongoDB query, like these:

MONGODB (0ms) mydb['templates'].find({:_type=>{"$in"=>["DS::QPM::Template"]},
 :_id=>BSON::ObjectId('4e9f815f10b6110e9b000001')}).limit(-1)

The find queries are fine. It's when it dumps 5mb of update query to my console that it starts annoying me. Anyone know how to turn these off? My Google-fu is not strong enough to find an answer to this.


Solution

  • When you connect to MongoMapper, just add a :logger option. Something like this:

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

    That will make it log to the regular Rails log. See here for the docs on this: http://api.mongodb.org/ruby/current/Mongo/Connection.html#constructor_details

    Note though that this says the default is "nil", so I'm not sure why your instance is logging anything at all without you having explicitly set it up to do so.