I followed this page to see mongoDB queries. As a result I could see Moped log.
But I can't see raw mongoDB queries.
How can I display MongoDB queries in the rails console/server
I did like the below.
# in [rails root]/config/environments/development.rb Mongoid.logger.level = Logger::DEBUG Moped.logger.level = Logger::DEBUG Mongoid.logger = Logger.new("#{Rails.root}/log/mongoid_development.log") Moped.logger = Logger.new("#{Rails.root}/log/moped_development.log") # in [rails root]/log/mongoid_development.log # show nothing. # in [rails root]/log/moped_development.log MOPED: [ip address]:27017 QUERY database=[database name] collection=[collection name] selector={"$query"=>{"screen_name"=>"ts_3156"}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (54.6286ms)
How can I see raw mongoDB queries with Mongoid?
I want to see like the below.
db.[collection name].find({ $query: {"screen_name"=>"ts_3156"}, $orderby: {:_id=>1} })
I can see raw mongoDB queries in /var/log/mongo/mongo.log.
But I want to see raw queries in ORM(Mongoid)'s log.
To view the query plan information for a given query, you can use db. collection. explain() or the cursor. explain() .
In MongoDB, find() method is used to select documents in a collection and return a cursor to the selected documents. Cursor means a pointer that points to a document, when we use find() method it returns a pointer on the selected documents and returns one by one.
The only foolproof method of determining whether a collection scan was performed is to compare the index keys with the match criteria from the query.
I think I got an answer. This is follow dsims answer and also from what I've seen in the documentation regarding logging.
I have an initialize file (config/initializers/mongoid.rb) and in there I have:
Mongoid.logger = Logger.new($stdout) Mongo::Logger.logger = Logger.new($stdout)
It dumps out the mongo info the console. You probably want to change this for a production environment. But while developing I like to be able to see what the DB is doing. Especially because I'm brand new to MongoDb.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With