[MongoDB] Thedescriptionofindex (1)

Source: Internet
Author: User
Fromthisblog, westarttotalkabouttheindexin1_database, whichissimilartothetraditionaldatabase. Generallyspeaking, Ghost, sodoesMongoDB. InMongoDB, thefield_idh

From this blog, we start to talk about the index in mongo Database, which is similar to the traditional database. generally speaking, if the index need to be created in the traditional database, so does MongoDB. in MongoDB, the field _ id h

From this blog, we start to talk about the index in mongo Database, which is similar to the traditional database. generally speaking, if the index need to be created in the traditional database, so does MongoDB. in MongoDB, the field '_ id' has been set index by default and this index is so special that it cannot be deleted into T for Capped Collections.

Before studying the index, now we create 10000 test records as follows.

1 Create index

In mongodb, using the function ensureIndex () to create tne index, for example:

Db. test. ensureIndex ({name: 1}) means to create index for name

2. Use index

Generally speaking, there is five way to create index based on the practice condition.

2.1 Common Index

Query the result before creating index and after.

Some explanation of result field:

Cursor: value [BasicCursor or BtreeCursor], the later explain this query has used index.

Nscanned: the number of index of having scan.

N: return the number of document, namely return the line

Millis: the total time of finishing this query, unit millinus seconds.

IndexBounds: if not null, it will describe the index item,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.