How to find queries not using indexes or slow in mongodb

后端 未结 6 1348
轻奢々
轻奢々 2020-12-08 05:00

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:

         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 05:42

    You can use the command line tool mongotail to read the log from the profiler within a console and with a more readable format.

    First activate the profiler and set the threshold in milliseconds for the profile to consider an operation to be slow. In the following example the threshold is set to 10 milliseconds for a database named "sales":

    $ mongotail sales -l 1
    Profiling level set to level 1
    $ mongotail sales -s 10
    Threshold profiling set to 10 milliseconds
    

    Then, to see in "real time" the slow queries, with some extra information like the time each query took, or how many registries it need to "walk" to find a particular result:

    $ mongotail sales -f -m millis nscanned docsExamined
    2016-08-11 15:09:10.930 QUERY   [ops] : {"deleted": {"$exists": false}, "prod_id": "367133"}. 8 returned. nscanned: 344502. millis: 12
    2016-08-11 15:09:10.981 QUERY   [ops] : {"deleted": {"$exists": false}, "prod_id": "367440"}. 6 returned. nscanned: 345444. millis: 12
    ....
    

提交回复
热议问题