Get the App
SLTechnology News&Howtos  ›  Database  › 

How to view the execution plan method in MongoDB

Shulou Source: shulou.com Published: 2022-05-31 21:13:47 10月09日 Update

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.

Tags: Index method content analysis specialty small and medium information rich content slogan name name field character object that is meaning location data database quantity Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS MySQL Apple Linux