In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. explain function
The explain function can provide a lot of information about queries, and if it's a slow query, it's the most important diagnostic tool. For example:
Query on indexed fields:
> db.post.find({"loc.city":"ny"}).explain() { "cursor" : "BtreeCursor loc.city_1", "isMultiKey" : false, "n" : 0, "nscannedObjects" : 0, "nscanned" : 0, "nscannedObjectsAllPlans" : 0, "nscannedAllPlans" : 0, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 1, "indexBounds" : { "loc.city" : [ [ "ny", "ny" ] ] }, "server" : "localhost.localdomain:27017", "filterSet" : false } >
Query on fields without indexes:
> db.post.find({"name":"joe"}).explain() { "cursor" : "BasicCursor", "isMultiKey" : false, "n" : 2, "nscannedObjects" : 15, "nscanned" : 15, "nscannedObjectsAllPlans" : 15, "nscannedAllPlans" : 15, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "server" : "localhost.localdomain:27017", "filterSet" : false } >
Compare the two queries above, and explain the fields in the explain result:
"cursor":"BasicCursor" indicates that no index is used in this query;"BtreeCursor loc.city" indicates that the index on loc.city is used;
"isMultikey" indicates whether multikey indexing is used;
"n": Number of documents returned by this query;
"nscannedObjects": indicates the number of times the actual document is actually found on disk according to the index pointer;
"nscanned": if there is no index, this number is the number of index entries searched;
"scanAndOrder": whether the result set is sorted;
"indexOnly": whether the index can be completed by using the index;
"nYields": the query pauses if there is a write operation in the middle of the query; this field represents the number of times the query pauses due to write operations;
" millis": the number of times spent on this query, the smaller the number, the higher the query efficiency;
"indexBounds": This field describes the usage of the index and gives the range of index traversal.
"filterSet" : whether to use and index filtering;
2. Hint function
If you find that the index used by MongoDB is inconsistent with your desired index, You can use the hit function to force MongoDB to use a specific index. for example
>db.users.find({"age":1,"username":/.*/}). hint({"username":1,"age":1})
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.