Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mongodb slow query

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Enable the Profiling function

1. Set it directly in the startup parameters

Add-profile=1 when you start MongoDB

You can also slow query time (that is, how much time greater than is recorded in the slow query)-slowms 200

two。 You can get the current Profile level through the db.getProfilingLevel () command

Db.getProfilingLevel ()

0-not enabled

1-record slow commands (default is > 100ms)

2-record all commands

Db.setProfilingLevel (level, slowms)

Db.setProfilingLevel (1,10)

3. Query slow query records

Db.system.profile.find ()

List Profile records whose execution time is longer than a certain limit (5ms):

> db.system.profile.find ({millis: {$gt: 5}})

4. Detailed explanation of slow query parameters

Ts- when the command is executed.

Millis Time- the command takes time to execute and is recorded in milliseconds.

Info- details of this command.

Query- indicates that this is a query query operation.

Ntoreturn- the number of records required to be returned by the query client. For example, the findOne () command executes with a ntoreturn of 1. 0. Ntoreturn is n when there is limit (n) condition.

Query- specific query conditions (such as x > 3).

Nscanned- the number of records scanned by this query.

Reslen- returns the size of the result set.

Nreturned- the actual result set returned by this query.

Update- indicates that this is a update update operation.

Fastmod-Indicates a fast modify operation. See Updates. These operations are normally quite fast.

Fastmodinsert-indicates a fast modify operation that performed an upsert.

Upsert- shows that the upsert parameter of update is true. The function of this parameter is to insert a record with the condition of update if the record of update does not exist.

Moved- indicates whether the update has moved the data on the hard disk. If the new record is shorter than the original record, it usually does not move the current record. If the new record is longer than the original record, it may move the record to another location, which will lead to the update of the relevant index. More disk operations, coupled with index updates, will make such operations slower.

Insert- this is an insert insert operation.

Getmore- this is a getmore operation, getmore usually occurs in a query with a large result set, the first query returns part of the results, and the subsequent results are obtained through getmore.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report