Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i view queries being executed by my mongodb?

Tags:

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?

like image 871
Kamilski81 Avatar asked Feb 20 '13 00:02

Kamilski81


People also ask

How can I see what queries are running in MongoDB?

The db. currentOp() command provides means to find all the queries that are currently running on your MongoDB server. The optional fields can be further leveraged to help filter the results to specific criteria.

Where are MongoDB commands executed?

To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.

How can you view the execution performance statistics for a query?

You can also view access the live query execution plan by right-clicking on a selected query in Management Studio and then click Include Live Query Statistics.

How do you identify a query performing a full scan on MongoDB?

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.

Which command can be used to show existing database when MongoDB is running?

Listing all the databases in mongoDB console is using the command show dbs .


1 Answers

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/

like image 50
Brandon Black Avatar answered Sep 22 '22 01:09

Brandon Black