정의
enableShardingThe
enableShardingcommand explicitly creates a database.팁
In
mongosh, this command can also be run through thesh.enableSharding()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
구문
명령은 다음과 같은 구문을 가집니다:
권장. 생성할 데이터베이스를 지정합니다:
db.adminCommand( { enableSharding: "<database name>" } ) 선택적으로 명령에 프라이머리 샤드 사양을 포함할 수 있지만, 이는 권장되지 않습니다.
db.adminCommand( { enableSharding: "<database name>", primaryShard: "<shard name>" } )
You can only run the enableSharding command on the admin database from a mongos instance.
명령 필드
이 명령은 다음 필드를 사용합니다.
필드 | 유형 | 설명 |
|---|---|---|
문자열 | 사용하려는 데이터베이스. 데이터베이스가 존재하지 않는 경우 생성됩니다. | |
문자열 | 선택 사항입니다. 데이터베이스의 프라이머리 샤드이며 여기에는 이 데이터베이스에 대한 샤딩되지 않은 컬렉션이 포함되어 있습니다. 일반적으로 프라이머리 샤드를 명시적으로 지정하는 것보다 밸런서가 프라이머리 샤드를 대신 선택하도록 하는 것이 좋습니다. 경고 팁 일반적으로 프라이머리 샤드를 지정할 필요는 없습니다. 밸런서가 대신 프라이머리 샤드를 선택하도록 허용합니다. |
반환
이 명령은 작업 상태가 포함된 문서를 반환합니다.
행동
쓰기 고려
mongos uses "majority" for the enableSharding command and its helper sh.enableSharding().
프라이머리 샤드
일반적으로 명령에 프라이머리 샤드를 지정할 필요가 없습니다. 대신 밸런서가 프라이머리 샤드를 선택하도록 허용합니다.
However, if you do specify the primaryShard in the command for a database and the database is already sharding enabled with a different primary shard, the operation returns an error and the primary shard for the database remains as before. To change the primary shard for a database, use movePrimary instead.
예시
mongos 에서 실행되는 다음 명령은 shardTest 데이터베이스를 생성합니다.
db.adminCommand( { enableSharding: "shardTest" } )