Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find queries not using indexes or slow in mongodb

is there a way to find queries in mongodb that are not using Indexes or are SLOW? In MySQL that is possible with the following settings inside configuration file:

log-queries-not-using-indexes = 1 log_slow_queries = /tmp/slowmysql.log 
like image 301
DmitrySemenov Avatar asked Aug 26 '13 19:08

DmitrySemenov


People also ask

How does MongoDB detect slow queries?

One can identify slow queries in MongoDB by enabling the profiler and configuring it to its some specifications or executing db. currentOp() on a running mongod instance. By looking at the time parameters on the returned result, we can identify which queries are lagging.

How do I see what queries are running in MongoDB?

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.

Does indexing improve query performance MongoDB?

Performance. Because the index contains all fields required by the query, MongoDB can both match the query conditions and return the results using only the index. Querying only the index can be much faster than querying documents outside of the index.

How do you check if indexes are being used in MongoDB?

You can find all the available indexes in a MongoDB collection by using the getIndexes method. This will return all the indexes in a specific collection. Result: The output contains the default _id index and the user-created index student name index.


1 Answers

The equivalent approach in MongoDB would be to use the query profiler to track and diagnose slow queries.

With profiling enabled for a database, slow operations are written to the system.profile capped collection (which by default is 1Mb in size). You can adjust the threshold for slow operations (by default 100ms) using the slowms parameter.

like image 177
Stennie Avatar answered Oct 21 '22 11:10

Stennie