mongodb怎么查看索引

286次阅读
没有评论

mongodb怎么查看索引

MongoDB提供了查看索引信息的方法:getIndexes()方法可以用来查看集合的所有索引,totalIndexSize()查看集合索引的总大小,db.system.indexes.find()查看数据库中所有索引信息。

1、查看集合中的索引getIndexes()

db.COLLECTION_NAME.getIndexes()

如,查看集合sites中的索引:

>db.sites.getIndexes()
[
  {
	"v" : 1,
	"key" : {
	  "_id" : 1
	},
	"name" : "_id_",
	"ns" : "newDB.sites"
  },
  {
	"v" : 1,
	"key" : {
	  "name" : 1,
	  "domain" : -1
	},
	"name" : "name_1_domain_-1",
	"ns" : "newDB.sites"
  }
]

2、查看集合中的索引大小totalIndexSize()

db.COLLECTION_NAME.totalIndexSize()

如,查看集合sites索引大小:

> db.sites.totalIndexSize()
16352

3、查看数据库中所有索引db.system.indexes.find()

db.system.indexes.find()

如,当前数据库的所有索引:

> db.system.indexes.find()
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:MongoDB2022-12-06发表,共计589字。
新手QQ群:570568346,欢迎进群讨论 Python51学习