[MongoDB] The description of index (1), mongodbdescription

Source: Internet
Author: User

[MongoDB] The description of index (1), mongodbdescription

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,


The nature of the goods and description of the goods are not the same thing

They are all goods descriptions, but the former focuses on the properties of the goods, and the latter includes packaging and other content related to the goods.

Describes how the indexOf () method is executed.

IndexOf () is a method of a string object. It has been reloaded four times. Its usage is as follows:
Int indexOf (int ch)
Returns the index of the first occurrence of the specified character in this string.
Int indexOf (int ch, int fromIndex)
Searches from the specified index and returns the index at the specified character for the first time in this string.
Int indexOf (String str)
Returns the index of the first occurrence of the specified substring in this string.
Int indexOf (String str, int fromIndex)
Returns the index of the first occurrence of the specified substring from the specified index.
This section is taken from jdk1.5API
Source code:
Public int indexOf (int ch, int fromIndex ){
Int max = offset + count;
Char v [] = value;

If (fromIndex <0 ){
FromIndex = 0;
} Else if (fromIndex> = count ){
// Note: fromIndex might be near-1 >>> 1.
Return-1;
}

Int I = offset + fromIndex;
If (ch <Character. MIN_SUPPLEMENTARY_CODE_POINT ){
// Handle most cases here (ch is a BMP code point or
// Negative value (invalid code point ))
For (; I <max; I ++ ){
If (v [I] = ch ){
Return I-offset;
}
}
Return-1;
}

If (ch <= Character. MAX_CODE_POINT ){
// Handle supplementary characters here
Char [] surrogates = Character. toChars (ch );
For (; I <max; I ++ ){
If (v [I] = surrogates [0]) {
If (I + 1 = max ){
Break;
}
If (v [I + 1] = surrogates [1]) {
Return I-offset;
}
}
}
}
Return-1;
}... Remaining full text>

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.