1 Where to use the index
Everything that involves finding a place needs an index.
2 Types of mongodb indexes
2.1 Single field index
Same as mysql.
db.person.ensureIndex({age:1});
2.2 Combined Index
Same as mysql.
db.person.ensureIndex({age:1, name:1});
2.3 Multi-key index
When the indexed field is an array, mongodb creates an index for each element in the array.
{"name" : "jack", "age" : 19, habbit: ["football, runnning"]}
db.person.ensureIndex( {habbit: 1} ) // 自动创建多key索引
db.person.find( {habbit: "football"} )
2.4 Text Index
Full text index.
3 The condition of mongodb query is also a json object
db.user.find({"name":{"$gte":18, "$lte":20}});