With
同
ActiveRecord::Base.logger = Logger.new(STDOUT)
you can view SQL statements in Rails Console,related here, but that require ActiveRecord , with mongo_mapper you don't have ActiveRecord, so how view debug of querys ?
你可以在Rails Console中查看SQL语句,这里有相关的,但是需要ActiveRecord,mongo_mapper你没有ActiveRecord,那么如何查看查询调试?
1 个解决方案
#1
1
Although this is old I'm adding an answer here for anyone who comes looking later.
虽然这已经很久了,但我在这里为那些后来看的人添加了一个答案。
Based on this the answer is simple. In your config/initializers/mongo.rb
file change your connection string as follows:
基于此,答案很简单。在config / initializers / mongo.rb文件中,更改连接字符串,如下所示:
logger = Logger.new(STDOUT)
MongoMapper.connection = Mongo::Connection.new('mongo.example.com', 27017, :logger => logger)
Restart Rails and the Mongo query strings now show up in the logger.
重新启动Rails,Mongo查询字符串现在显示在记录器中。
#1
1
Although this is old I'm adding an answer here for anyone who comes looking later.
虽然这已经很久了,但我在这里为那些后来看的人添加了一个答案。
Based on this the answer is simple. In your config/initializers/mongo.rb
file change your connection string as follows:
基于此,答案很简单。在config / initializers / mongo.rb文件中,更改连接字符串,如下所示:
logger = Logger.new(STDOUT)
MongoMapper.connection = Mongo::Connection.new('mongo.example.com', 27017, :logger => logger)
Restart Rails and the Mongo query strings now show up in the logger.
重新启动Rails,Mongo查询字符串现在显示在记录器中。