AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.
Docs Menu

listDatabases (데이터베이스 명령)

listDatabases

listDatabases 명령은 모든 기존 데이터베이스의 정렬되지 않은 목록과 각 데이터베이스 에 대한 기본 통계를 반환합니다. admin 데이터베이스 에 대해 listDatabases 명령을 실행 해야 합니다.

이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.

  • MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스

참고

이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하세요.

db.adminCommand(
{
listDatabases: 1
}
)

값(예: 1은는 명령의 출력에 영향을 주지 않습니다.

이 명령은 다음과 같은 선택적 필드를 사용할 수 있습니다.

필드
유형
설명

filter

문서

선택 사항입니다. 나열되는 데이터베이스를 결정하는 쿼리 조건자입니다.

listDatabases 출력의 모든 필드에 조건을 지정할 수 있습니다.

  • name

  • sizeOnDisk

  • empty

  • shards

nameOnly

부울

선택 사항. 명령이 데이터베이스 이름만 반환할지, 아니면 데이터베이스 이름과 크기 정보를 모두 반환할지를 나타내는 플래그입니다.

기본값 은 false이므로 listDatabases 은 각 데이터베이스 의 이름과 크기 정보를 반환합니다.

authorizedDatabases

부울

선택 사항입니다. 액세스 제어가 활성화된 경우 사용자 권한을 기반으로 반환되는 데이터베이스를 결정하는 플래그입니다.

  • authorizedDatabases가 지정되지 않은 경우 및

    • If the user has listDatabases action on the cluster resource, listDatabases command returns all databases.

    • If the user does not have listDatabases action on the cluster, listDatabases returns only the databases for which the user has privileges (including databases for which the user has privileges on specific collections).

  • If authorizedDatabases is true, listDatabases returns only the databases for which the user has privileges (including databases for which the user has privileges on specific collections).

  • authorizedDatabasesfalse인 경우 및

자세한 내용은 동작을 참조하세요.

comment

any

선택 사항. 이 명령에 첨부할 사용자 제공 코멘트입니다. 설정되면 이 설명은 다음 위치에서 이 명령의 레코드와 함께 표시됩니다.

댓글은 유효한 모든 BSON types (문자열, 정수, 객체, 배열 등)이 될 수 있습니다.

인증 이 활성화되면 listDatabases 명령은 명령을 실행하는 사용자에게 할당된 권한과 authorizedDatabases 명령 옵션에 따라 다른 값을 반환합니다.

  • authorizedDatabases가 지정되지 않은 경우 및

    • If the user has listDatabases action on the cluster resource, listDatabases command returns all databases.

    • If the user does not have listDatabases action on the cluster, listDatabases command returns only the databases for which the user has privileges (including databases for which the user has privileges on specific collections).

  • If authorizedDatabases is true, listDatabases command returns only the databases for which the user has privileges (including databases for which the user has privileges on specific collections).

  • authorizedDatabasesfalse인 경우 및

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

유형: 배열

단일 데이터베이스에 대한 정보를 각각 담고 있는 문서 배열입니다.

listDatabases.databases.name

유형: 문자열

데이터베이스의 이름입니다.

listDatabases.databases.sizeOnDisk

유형: 유형: 정수

디스크에 있는 데이터베이스 파일의 총 크기(바이트 단위)입니다.

listDatabases.databases.empty

유형: 부울

데이터베이스가 비어 있는지 여부를 지정합니다.

listDatabases.databases.shards

유형: 문서

shards 문서의 각 요소는 키가 해당 샤드의 collection 이름을 제공하고 값이 collection 크기(바이트)를 나타내는 필드로 구성됩니다.

shards nameOnly: false인 경우에만 출력에 나타납니다.

자세한 내용은 샤딩된 클러스터를 참조하세요.

listDatabases.totalSize

유형: 유형: 정수

모든 sizeOnDisk 필드의 합계입니다(바이트 단위).

listDatabases.totalSizeMb

유형: 유형: 정수

모든 sizeOnDisk 필드의 합계로, 메가바이트 단위로 표시됩니다.

listDatabases.ok

유형: 유형: 정수

명령의 반환 값입니다. 값이 1이면 성공입니다.

이 페이지 평가하기