중요
Mongo쉬 방법
This page documents a mongosh method. This is not the documentation for a language-specific driver, such as Node.js.
MongoDB API 드라이버의 경우 언어별 MongoDB 드라이버 설명서를 참조하세요.
정의
db.adminCommand(command)admin데이터베이스에 대해 지정된 데이터베이스 명령을 실행하는 헬퍼를 제공합니다.
호환성
이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
참고
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
행동
db.adminCommand() runs commands against the admin database regardless of the database context in which it runs. The following commands are equivalent:
db.getSiblingDB("admin").runCommand(<command>) db.adminCommand(<command>)
사용 가능한 관리 데이터베이스 명령 목록은 데이터베이스 명령을 참조하세요.
참고
authorization과 함께 실행 중인 mongod 또는 mongos의 경우, 권한 부여된 사용자에게 데이터베이스 명령을 실행할 수 있는 적절한 특권이 있어야 합니다. 보안 요구 사항에 대한 자세한 내용은 명령에 대한 참고 문서를 참조하세요.
응답
이 메서드는 다음 필드가 포함된 응답 문서를 반환합니다.
필드 | 설명 |
|---|---|
<command result> | 실행된 |
| 명령이 성공했는지( |
| 작업의 논리적 시간입니다. MongoDB는 논리적 시간을 사용하여 작업의 순서를 지정합니다. 복제본 세트 및 샤딩된 클러스터에만 해당됩니다. 명령이 oplog 엔트리(예시: 읽기 작업)를 생성하지 않는 경우 작업은 논리적 시계를 진행하지 않습니다. 이 경우
인과적으로 일관적인 세션과 관련된 작업의 경우 MongoDB 드라이버는 논리적 시간을 사용하여 읽기 작업 및 |
| 서명된 클러스터 시간을 반환하는 문서입니다. 클러스터 시간은 작업 순서를 지정하는 데 사용되는 논리적 시간입니다. 복제본 세트 및 샤딩된 클러스터에만 해당됩니다. 내부용으로만 사용하세요. 이 문서에는 다음 필드가 포함되어 있습니다:
|
예시
killOp
The following example uses the db.adminCommand() method to execute a killOp command to terminate an operation with opid 724. killOp is an administrative command and must be run against the admin database.
db.adminCommand( { "killOp": 1, "op": 724 } )
리네임 컬렉션
The following example uses db.adminCommand() to execute the renameCollection administrative database command to rename the orders collection in the test database to orders-2016.
db.adminCommand( { renameCollection: "test.orders", to: "test.orders-2016" } )
createUser
The following example uses the db.adminCommand() method to create a user named bruce with the dbOwner role on the admin database.
팁
메서드/명령 호출에서 암호를 직접 지정하는 대신 passwordPrompt() 메서드를 다양한 사용자 인증/관리 메서드/명령과 함께 사용하여 암호를 묻는 메시지를 표시할 수 있습니다. 그러나 이전 버전의 mongo 셸에서와 마찬가지로 비밀번호를 직접 지정할 수도 있습니다.
db.adminCommand( { createUser: "bruce", pwd: passwordPrompt(), // or <cleartext password> roles: [ { role: "dbOwner", db: "admin" } ] } )