정의
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
참고
이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하세요.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
구문
db.adminCommand( { listDatabases: 1 } )
값(예: 1은는 명령의 출력에 영향을 주지 않습니다.
명령 필드
이 명령은 다음과 같은 선택적 필드를 사용할 수 있습니다.
필드 | 유형 | 설명 |
|---|---|---|
| 문서 | 선택 사항입니다. 나열되는 데이터베이스를 결정하는 쿼리 조건자입니다.
|
| 부울 | 선택 사항. 명령이 데이터베이스 이름만 반환할지, 아니면 데이터베이스 이름과 크기 정보를 모두 반환할지를 나타내는 플래그입니다. 기본값 은 |
| 부울 | 선택 사항입니다. 액세스 제어가 활성화된 경우 사용자 권한을 기반으로 반환되는 데이터베이스를 결정하는 플래그입니다.
자세한 내용은 동작을 참조하세요. |
| any | 선택 사항. 이 명령에 첨부할 사용자 제공 코멘트입니다. 설정되면 이 설명은 다음 위치에서 이 명령의 레코드와 함께 표시됩니다.
댓글은 유효한 모든 BSON types (문자열, 정수, 객체, 배열 등)이 될 수 있습니다. |
행동
인증 이 활성화되면 listDatabases 명령은 명령을 실행하는 사용자에게 할당된 권한과 authorizedDatabases 명령 옵션에 따라 다른 값을 반환합니다.
authorizedDatabases가 지정되지 않은 경우 및If the user has
listDatabasesaction on the cluster resource,listDatabasescommand returns all databases.If the user does not have
listDatabasesaction on the cluster,listDatabasescommand returns only the databases for which the user has privileges (including databases for which the user has privileges on specific collections).
If
authorizedDatabasesistrue,listDatabasescommand returns only the databases for which the user has privileges (including databases for which the user has privileges on specific collections).authorizedDatabases가false인 경우 및If the user has
listDatabasesaction on the cluster,listDatabasescommand returns all databasesIf the user does not have
listDatabasesaction on the cluster,listDatabasescommand errors with insufficient permissions.
클라이언트 연결 해제
If the client that issued listDatabases disconnects before the operation completes, MongoDB marks listDatabases for termination using killOp.
복제본 세트 구성원 국가 제한
To run on a replica set member, listDatabases operations require the member to be in PRIMARY or SECONDARY state. If the member is in another state, such as STARTUP2, the operation errors.
예시
데이터베이스 이름 및 크기 나열
admin 데이터베이스 에 대해 listDatabases 를 실행합니다.
db.adminCommand( { listDatabases: 1 } )
다음은 listDatabases 결과의 예시 입니다.
{ "databases" : [ { "name" : "admin", "sizeOnDisk" : 83886080, "empty" : false }, { "name" : "local", "sizeOnDisk" : 83886080, "empty" : false }, { "name" : "test", "sizeOnDisk" : 83886080, "empty" : false } ], "totalSize" : 251658240, "totalSizeMb" : 251, "ok" : 1 }
데이터베이스 이름만 나열
admin 데이터베이스 에 대해 listDatabases 를 실행합니다. nameOnly: true 옵션을 지정합니다.
db.adminCommand( { listDatabases: 1, nameOnly: true} )
출력 예시:
{ "databases" : [ { "name" : "admin" }, { "name" : "local" }, { "name" : "test" } ], "ok" : 1 }
필터와 일치하는 데이터베이스 목록
admin 데이터베이스 에 대해 listDatabases 를 실행합니다. 지정된 필터하다 기준과 일치하는 데이터베이스만 나열하려면 filter 옵션을 지정합니다.
예를 예시 다음은 listDatabases 가 지정된 과 이름이 일치하는 데이터베이스에 대한 정보만 반환하도록 필터하다 regular expression 를 지정합니다.
db.adminCommand( { listDatabases: 1, filter: { "name": /^rep/ } } )
샤딩된 클러스터
인스턴스 에 대해 mongos 실행되는listDatabases 경우:
nameOnly: false인 경우 각 데이터베이스의 요약 문서에shards내장된 문서를 추가하고local데이터베이스를 제외합니다.
shards 내장된 문서의 각 요소는 키가 해당 샤드의 컬렉션 이름을 제공하고 값이 컬렉션 크기(바이트)를 나타내는 필드로 구성됩니다.
sizeOnDisk 필드는 나열된 모든 컬렉션 및 인덱스의 총 크기를 나타냅니다.
예를 들면 다음과 같습니다.
{ "databases" : [ { "name" : "admin", "sizeOnDisk" : 16384, "empty" : false, "shards" : { "config" : 16384 } }, { "name" : "config", "sizeOnDisk" : 176128, "empty" : false, "shards" : { "clients" : 28672, "patients" : 8192, "config" : 139264 } }, { "name" : "test", "sizeOnDisk" : 12288, "empty" : false, "shards" : { "clients" : 12288 } } ], "totalSize" : 204800, "totalSizeMb" : 0, "ok" : 1 }
출력
listDatabases.databases.shards유형: 문서
shards문서의 각 요소는 키가 해당 샤드의 collection 이름을 제공하고 값이 collection 크기(바이트)를 나타내는 필드로 구성됩니다.shardsnameOnly: false인 경우에만 출력에 나타납니다.자세한 내용은 샤딩된 클러스터를 참조하세요.