정의
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: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
중요
이 명령은 M0 및 Flex 클러스터에서 지원되지 않습니다. 자세한 내용은 지원되지 않는 명령을 참조하세요.
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().
프라이머리 샤드
일반적으로 명령에 프라이머리 샤드를 지정할 필요가 없습니다. 대신 밸런서가 프라이머리 샤드를 선택하도록 허용합니다.
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()를 실행합니다.