복붙노트

[MONGODB] MongoDB의에서 인덱스의 목록?

MONGODB

MongoDB의에서 인덱스의 목록?

쉘에서 MongoDB를의 컬렉션 인덱스의 목록을 볼 수있는 방법이 있습니까? 내가 http://www.mongodb.org/display/DOCS/Indexes를 통해 읽을 수 있지만 난 아무것도 볼 해달라고

해결법

  1. ==============================

    1.쉘에서 :

    쉘에서 :

    db.test.getIndexes()
    

    쉘에 대한 도움말 당신은 시도해야합니다 :

    help;
    db.help();
    db.test.help();
    
  2. ==============================

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

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

    use "yourdbname"
    
    db.system.indexes.find()
    
  3. ==============================

    3.모든 인덱스를 나열 할 경우 :

    모든 인덱스를 나열 할 경우 :

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

    4.당신이 컬렉션을 사용해야합니다 :

    당신이 컬렉션을 사용해야합니다 :

    db.collection.getIndexes()
    

    http://docs.mongodb.org/manual/administration/indexes/#information-about-indexes

  5. ==============================

    5.당신은 그들의 크기도 함께 출력 모든 인덱스 할 수 있습니다

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

    db.collectionName.stats().indexSizes
    

    또한 ()이 db.collectionName.stats을 확인 당신에게 paddingFactor, 컬렉션의 크기와 내부 요소의 번호와 같은 흥미로운 정보를 많이 제공합니다.

  6. ==============================

    6.모든 컬렉션의 모든 인덱스를 찾을하려는 경우, 한 단계 더 나아가 복용, (여기 후안 카를로스 파라의 스크립트에서 수정)이 스크립트는 당신에게 인덱스 정보의 JSON 인쇄물을 포함하여 몇 가지 유용한 출력을 제공합니다 :

    모든 컬렉션의 모든 인덱스를 찾을하려는 경우, 한 단계 더 나아가 복용, (여기 후안 카를로스 파라의 스크립트에서 수정)이 스크립트는 당신에게 인덱스 정보의 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);
             });
    
    
        });
    
    });
    
  7. from https://stackoverflow.com/questions/2789865/a-list-of-indices-in-mongodb by cc-by-sa and MIT license