在实际应用中,我们有时候会遇到“MongoDB中查看集合和数据库里所有索引的方法是什么”这样的问题,我们该怎样来处理呢?下文给大家介绍了解决方法,希望这篇“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()
以上就是关于“MongoDB中查看集合和数据库里所有索引的方法是什么”的相关知识,感谢各位的阅读。