【MongoDB】The description of index(一),mongodbdescription

來源:互聯網
上載者:User

【MongoDB】The description of index(一),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 except 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與description of the goods是不是一回事

都是貨描,但是前者側重於貨物本身的屬性,後者包含封裝等所有與貨物有關的內容。
 
說明一下indexOf()方法的執行原理

indexOf(),是string對象的一個方法,被重載過4次,每一次的用法為:
int indexOf(int ch)
返回指定字元在此字串中第一次出現處的索引。
int indexOf(int ch, int fromIndex)
從指定的索引開始搜尋,返回在此字串中第一次出現指定字元處的索引。
int indexOf(String str)
返回第一次出現的指定子字串在此字串中的索引。
int indexOf(String str, int fromIndex)
從指定的索引處開始,返回第一次出現的指定子字串在此字串中的索引。
這段摘自jdk1.5API
原始碼:
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 a
// 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;
}...餘下全文>>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.