Kamilski81
Kamilski81

Reputation: 15127

How do i view queries being executed by my mongodb?

I keep on seeing this in my log/development.log, and I am wondering whether this query is actually being executed in my database:

MONGODB (0ms) socialcrunch_development['tags'].find({:_id=>"secrets"}).limit(-1).sort([[:_id, :asc]])

Ho can I see the queries being executed on my mongo db, so I can count them, should they all typically be .find commands, or should i being looking for something else?

Upvotes: 6

Views: 22900

Answers (1)

Brandon Black
Brandon Black

Reputation: 887

Print all active reads:

db.currentOp().inprog.forEach(
   function(d){
     if(d.waitingForLock && d.lockType != "read")
        printjson(d)
     })

Print all active writes:

db.currentOp().inprog.forEach(
   function(d){
     if(d.waitingForLock && d.lockType != "write")
        printjson(d)
     })

You can get a lot more granular if you like by using currentOp.op to filter by a specific operation type (insert, update, delete, etc).

Check out the following page from MongoDB.org's documentation for more info: http://docs.mongodb.org/manual/reference/current-op/

Upvotes: 13

Related Questions