MongoDB 索引 和 explain 的使用

索引基础

索引是对数据库表中一列或多列的值进行排序的一种结构,可以让我们查询数据库变得 更快。MongoDB 的索引几乎与传统的关系型数据库一模一样,这其中也包括一些基本的查 询优化技巧。

创建索引的命令

  • db.user.ensureIndex({"username":1})

获取当前集合的索引

  • db.user.getIndexes()

删除索引的命令

  • db.user.dropIndex({"username":1})

复合索引

  • db.user.ensureIndex({name:1,age:1})

解释执行

  • db.user.find({name:"王麻子"}).explain("executionStats")

相关文章

文章浏览阅读552次。com.mongodb.MongoQueryException: Quer...
文章浏览阅读635次,点赞9次,收藏8次。MongoDB 是一种 NoSQ...
文章浏览阅读2.1k次。和。_mongodb 日期类型
文章浏览阅读1.7k次。Scalestack等客户期待使用MongoDB Atla...
文章浏览阅读970次。SpringBoot整合中间件mongodb、ES_sprin...
文章浏览阅读673次。MongoDB 简介_尚医通sql