MongoDb -索引 + $type + 分析函数 explain

索引:

db.testCo2.ensureIndex({"name":1}); //普通索引

db.testCo2.reIndex();当前集合的所有index信息

db.testCo2.ensureIndex({“name”:1},{“unique”:true}); //唯一索引:

db.testCo2.getIndexes(); //查询所有的索引

db.testCo2.dropIndex("name_1_age_1"); //删除索引

//使用hint强制要求查询操作使用某个索引

db.testCo2.find({name:"cgh",age:23}).hint({name:1}) //强制使用索引



分析函数:

db.testCo2.find().explain();


$type 字段类型搜索

db.testCo2.find({

"name":{

"$type":10

}});

"_id" :ObjectId("5a03b44e73232118c78f3546"), 

"id" :"221",

"name" : null

}

Double 1

String 2

Object 3

Array 4

Binary data 5

Object id 7

Boolean 8

Date 9

Null 10

Regular expression 11

JavaScript code 13

Symbol 14

JavaScript code with scope 15

32-bit integer 16

Timestamp 17

64-bit integer 18

Min key 255

Max key 127

你可能感兴趣的:(MongoDb -索引 + $type + 分析函数 explain)