정의
sh.enableSharding(database, primaryShard)Explicitly creates a database. Use the
mongoshmethodsh.shardCollection()to shard collections on the database. Themongoshmethodsh.enableSharding()wraps theenableShardingcommand.중요
Mongo쉬 방법
This page documents a
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.데이터베이스 명령에 대해서는
enableSharding명령을 참조하십시오.MongoDB API 드라이버의 경우 언어별 MongoDB 드라이버 설명서를 참조하세요.
호환성
이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
중요
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
구문
The sh.enableSharding() has the following form:
sh.enableSharding( <database>, <primary shard> // Optional. )
Parameter
The sh.enableSharding() method takes the following parameter:
Parameter | 유형 | 설명 |
|---|---|---|
문자열 | 생성하려는 데이터베이스의 이름입니다. | |
문자열 | 선택 사항. 데이터베이스 의 프라이머리 샤드 입니다. 데이터베이스 의 모든 샤딩되지 않은 컬렉션에 대한 기본값 샤드 입니다. 경고: 일반적으로 프라이머리 샤드 를 지정해서는 안 됩니다. 클러스터 가 대신 프라이머리 샤드 를 선택하도록 허용합니다. |
행동
쓰기 고려
mongos uses "majority" for the enableSharding command and its helper sh.enableSharding().
프라이머리 샤드
In general, you should not need to specify the primaryShard in the command. Instead, allow the balancer to select the primary shard.
However, if you do specify the primary shard for a database and the database is already enabled for sharding 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 the movePrimary command instead.
예시
mongos에서 실행되는 다음 예시는 명시적으로 shardTest 데이터베이스를 생성합니다.
sh.enableSharding("shardTest")
확인하려면 sh.status()를 실행합니다.