"MongoDB" The description of index (a)

Source: Internet
Author: User
Tags create index

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 is created in the traditional database, so does MongoDB. In MongoDB, the field ' _id ' have been set index by default and this index was so special that it cannot be deleted except F or 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-to-create index based on the practice condition.

2.1 Common Index

Quer y 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 your index of having a 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 would describe the index item,

"MongoDB" The description of index (a)

Related Article

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.