欢迎投稿

今日深度:

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

【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;
}...余下全文>>
 

www.htsjk.Com true http://www.htsjk.com/shujukunews/4012.html NewsArticle 【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 tra...
评论暂时关闭