首页 技术 正文
技术 2022年11月16日
0 收藏 508 点赞 4,920 浏览 1596 个字

索引的限制:

索引名称不能超过128个字符

每个集合不能超过64个索引

复合索引不能超过31列

MongoDB 索引语法

db.collection.createIndex({ <field>: < 1 or -1 > })

db.collection.ensureIndex({ <field>: < 1 or -1 > })

db.collection.createIndex( { “filed”: sort } )

db.collection.createIndex( { “filed”: sort , “filed2”: sort } )

db.tab.ensureIndex({“id”:1})

db.tab.ensureIndex({“id”:1} ,{ name:”id_ind”})

db.tab.ensureIndex({“id”:1,”name”:1},{background:1,unique:1})

db.tab.ensureIndex( { “id” : “hashed” })

创建索引(两种方法)

filed :为键列

sort :为排序。1 为升序;-1为降序。

创建单列索引

创建索引并给定索引名称

后台创建唯一的复合索引

创建哈希索引

(更多参数 看文章底部)

db.tab.indexStats( { index: “id_ind” } )

db.runCommand( { indexStats: “tab”, index: “id_ind” } )

db.tab.getIndexes()

db.system.indexes.find()

(前2个似乎不能用,官方文档解释)

(not intended for production deployments)

查看索引

db.tab.totalIndexSize();

查看索引大小

db.tab.reIndex()

db.runCommand({reIndex:”tab”})

重建索引

db.tab.dropIndex(<indexname>)

db.tab.dropIndex(“id_1”)

db.tab.dropIndexes()

删除索引

<indexname>为getIndexes看到的索引名称

删除所有索引(注意!)

分析函数

db.tab.find({“name”:”kk50000″}).explain()

查询name=”kk50000”的执行分析

db.tab.find({“name”:”kk50000″}).explain(“queryPlanner”)

db.tab.find({“name”:”kk50000″}).explain(“Verbosity”)

db.tab.find({“name”:”kk50000″}).explain(“executionStats”)

db.tab.find({“name”:”kk50000″}).explain(“allPlansExecution”)

这3种方法执行结果完全包括上面这种的结果

db.tab.find({“name”:”kk50000″}).explain()  结果做分析:

“cursor” : “BasicCursor”,

“isMultiKey” : false,

“n” : 1,

“nscannedObjects” : 966423,

“nscanned” : 966423,

“nscannedObjectsAllPlans” : 966423,

“nscannedAllPlans” : 966423,

“scanAndOrder” : false,

“indexOnly” : false,

“nYields” : 7555,

“nChunkSkips” : 0,

“millis” : 4677,

“server” : “kk-ad:27017”,

“filterSet” : false

游标类型。BasicCurso(扫描), BtreeCursor(索引)

是否多键(组合)索引

返回行数

扫描行数

扫描行数

所有计划扫描的次数

所有计划扫描的次数

是否在内存中排序

耗时(毫秒)

服务器

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,996
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,510
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,353
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,137
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848