2010-05-07 6 views

답변

137

를 참조 해달라고 :

db.test.getIndexes() 

쉘 도움말은 당신이 시도해야합니다

help; 
db.help(); 
db.test.help(); 
13

그리고 당신은 당신의 데이터베이스에있는 모든 인덱스의 목록을 얻으려면 :

use "yourdbname" 

db.system.indexes.find() 
5

을 당신은 자신의 크기도 함께 출력 모든 인덱스 할 수 있습니다

또한
db.collectionName.stats().indexSizes 

db.collectionName.stats() 당신에게 많은 것을 제공하는지 확인 paddingFactor, 컬렉션의 크기 및 내부 요소 수와 같은 흥미로운 정보를 제공합니다.

4

모든 인덱스를 나열 할 경우 모든 컬렉션의 모든 인덱스를 찾을하려는 경우

db.getCollectionNames().forEach(function(collection) { 
    indexes = db[collection].getIndexes(); 
    print("Indexes for " + collection + ":"); 
    printjson(indexes); 
}); 
2

는, 한 단계 더 나아가 촬영을, (후안 카를로스 파라의 스크립트 here에서 수정)이 스크립트를 제공합니다 인덱스 세부 정보의 JSON 인쇄물을 포함한 유용한 출력물 :

// Switch to admin database and get list of databases. 
db = db.getSiblingDB("admin"); 
dbs = db.runCommand({ "listDatabases": 1}).databases; 


// Iterate through each database and get its collections. 
dbs.forEach(function(database) { 
db = db.getSiblingDB(database.name); 
cols = db.getCollectionNames(); 

// Iterate through each collection. 
cols.forEach(function(col) { 

    //Find all indexes for each collection 
    indexes = db[col].getIndexes(); 

    indexes.forEach(function(idx) { 
     print("Database:" + database.name + " | Collection:" +col+ " | Index:" + idx.name); 
     printjson(indexes); 
     }); 


    }); 

}); 
+0

이것은 정말 도움이 되겠지만'printjson (indexes);'는'printjson (id x); –