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

How to view the execution plan method in MongoDB

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you about how to view the implementation plan in MongoDB. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

> db.chenfeng.find ()

{"_ id": ObjectId ("5714419cf7c81959e12a904e"), "age": 1, "name": "duansf"}

{"_ id": ObjectId ("571441a3f7c81959e12a904f"), "age": 2, "name": "duansf"}

{"_ id": ObjectId ("571441a7f7c81959e12a9050"), "age": 3, "name": "duansf"}

{"_ id": ObjectId ("571441abf7c81959e12a9051"), "age": 4, "name": "duansf"}

{"_ id": ObjectId ("571442b0f7c81959e12a9052"), "age": 5, "name": "duansf"}

{"_ id": ObjectId ("571442bcf7c81959e12a9053"), "age": 6, "name": "duansf"}

>

> db.chenfeng.find () .explain ()

{

"cursor": "BasicCursor"

"isMultiKey": false

"n": 6

"nscannedObjects": 6

"nscanned": 6

"nscannedObjectsAllPlans": 6

"nscannedAllPlans": 6

"scanAndOrder": false

"indexOnly": false

"nYields": 0

"nChunkSkips": 0

"millis": 0

"server": "XCC-Duanshufeng:27017"

"filterSet": false

}

>

Add hint to force the use of indexing, which is much like a relational database:

> db.chenfeng.find () .hint ({age:6}) .explain ()

{

"cursor": "BtreeCursor idx_age_6"

"isMultiKey": false

"n": 6

"nscannedObjects": 6

"nscanned": 6

"nscannedObjectsAllPlans": 6

"nscannedAllPlans": 6

"scanAndOrder": false

"indexOnly": false

"nYields": 1

"nChunkSkips": 0

"millis": 135

"indexBounds": {

"age": [

[

{

"$minElement": 1

}

{

"$maxElement": 1

}

]

]

}

"server": "XCC-Duanshufeng:27017"

"filterSet": false

}

Field description:

Cursor: returns the cursor type. Having BasicCursor and BtreeCursor,BtreeCursor means that the index is used

Nscanned: number of rows scanned for document

NscannedObjects: number of objects scanned

N: number of document lines returned

Millis: time consuming (milliseconds)

IndexBounds: if not empty, indicates the index information used by this query

The name of the server where server:MongoDB is located, and 27017 is the port number.

Restrictions on the index:

Index name cannot exceed 128 characters

Each collection cannot have more than 64 indexes

Composite index cannot exceed 31 columns

The above is how to view the implementation plan method in the MongoDB shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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

Wechat

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

12
Report