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)