您现在的位置是:课程教程文章

mongodb怎么查看索引

2023-12-18 18:49课程教程文章 人已围观

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()
课程教程:mongodb怎么查看索引

上一篇:mongodb为什么数据库?

下一篇:没有了

站点信息

  • 文章统计篇文章