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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容