mongodb创建索引
来源:互联网 发布:最新司令部升级数据 编辑:程序博客网 时间:2024/05/20 19:45
1. mongodb中如果查找在1000000数据中,查找某一个数据,如果查找userId为1的我们来看看耗时:
db.visitLog.find({"userId" : 9}).explain()
"executionStats" : { "executionSuccess" : true, "nReturned" : 2, "executionTimeMillis" : 406, "totalKeysExamined" : 0, "totalDocsExamined" : 1000008, "executionStages" : { "stage" : "COLLSCAN", "filter" : { "userId" : { "$eq" : 9 } }, "nReturned" : 2, "executionTimeMillisEstimate" : 354, "works" : 1000010, "advanced" : 2, "needTime" : 1000007, "needYield" : 0, "saveState" : 7817, "restoreState" : 7817, "isEOF" : 1, "invalidates" : 0, "direction" : "forward", "docsExamined" : 1000008 }
执行时间406毫秒,注意这里userId为9,也就是数据开始的第九个"executionStats" : { "executionSuccess" : true, "nReturned" : 1, "executionTimeMillis" : 54700, "totalKeysExamined" : 0, "totalDocsExamined" : 1000008, "executionStages" : { "stage" : "COLLSCAN", "filter" : { "userId" : { "$eq" : 999999 } }, "nReturned" : 1, "executionTimeMillisEstimate" : 375, "works" : 1000010, "advanced" : 1, "needTime" : 1000008, "needYield" : 0, "saveState" : 7819, "restoreState" : 7819, "isEOF" : 1, "invalidates" : 0, "direction" : "forward", "docsExamined" : 1000008 }, "allPlansExecution" : [] }
好了,时间差别很大,因为mongodb从开始一个个查找,所以消耗时间过长
2.创建索引再看看
db.visitLog.ensureIndex({"userId":1}) //创建索引
"executionStats" : { "executionSuccess" : true, "nReturned" : 1, "executionTimeMillis" : 0, "totalKeysExamined" : 1, "totalDocsExamined" : 1, },
查询时间明显的提高了很多。阅读全文
0 0
- mongodb创建索引
- mongodb创建索引
- MongoDB 索引创建
- MongoDB索引创建
- mongodb创建索引
- mongodb索引创建
- MongoDB-创建索引
- mongodb创建索引
- MongoDB索引创建
- mongodb创建2D索引
- mongodb 索引创建、查询分析
- 关于Mongodb索引创建的一些体会
- 关于mongodb创建索引的一些经验总结
- mongoDB的基本操作之创建索引
- MongoDB索引的创建与删除
- MongoDB基于复制集创建索引
- mongodb 索引的创建于删除
- MongoDB普通索引和唯一索引区别与创建
- RTMP Handshake
- Java日期类型和字符串的相互转换
- 韩顺平jsp视频实战教程
- ubuntu12.4优化android虚拟机和安装intel显卡驱动
- kotlin 学习记录 基本语法(1)
- mongodb创建索引
- 计算请假工时,去除周六周末的时间
- 进程间通信--android binder
- C/C++开发环境(GTK/GNOME/Qt/KDE)
- Java 运算符
- CentOS7 安装Docker
- Kotlin是什么?
- 欢迎使用CSDN-markdown编辑器
- 如何设计和生成游戏的激活码