정의
convertToCapped경고
샤드 컬렉션에서는 이 명령을 실행하지 않음
MongoDB does not support the
convertToCappedcommand on sharded collections.The
convertToCappedcommand converts an existing, non-capped collection to a capped collection within the same database.
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
구문
명령은 다음과 같은 구문을 가집니다:
db.runCommand( { convertToCapped: <collection>, size: <capped size>, writeConcern: <document>, comment: <any> } )
명령 필드
이 명령은 다음 필드를 사용합니다.
필드 | 설명 |
|---|---|
convertToCapped (영문) | 변환할 기존 컬렉션의 이름입니다. |
size | 고정 사이즈 컬렉션의 최대 크기(단위: 바이트)입니다. |
쓰기 고려 | |
| 선택 사항. 이 명령에 첨부할 사용자 제공 코멘트입니다. 설정되면 이 설명은 다음 위치에서 이 명령의 레코드와 함께 표시됩니다.
댓글은 유효한 모든 BSON types (문자열, 정수, 객체, 배열 등)이 될 수 있습니다. |
convertToCapped takes an existing collection (<collection>) and transforms it into a capped collection with a maximum size in bytes, specified by the size argument (<capped size>).
During the conversion process, the convertToCapped command exhibits the following behavior:
MongoDB는 원래 컬렉션의 문서를 자연스러운 순서 로 탐색하고 문서를 새 고정 사이즈 컬렉션에 로드합니다.
고정 사이즈 컬렉션에 지정된
capped size가 원본 비고정 사이즈 컬렉션의 크기보다 작은 경우, MongoDB는 삽입 순서 또는 선입 선출 순서에 따라 고정 사이즈 컬렉션의 문서를 덮어씁니다.내부적으로, MongoDB는 collection을 변환하기 위해 다음 절차를 사용합니다.
cloneCollectionAsCapped명령은 고정 사이즈 컬렉션을 생성하고 데이터를 가져옵니다.MongoDB는 원본 collection을 삭제합니다.
renameCollection새로운 고정 사이즈 컬렉션의 이름을 원래 collection의 이름으로 변경합니다.
이는 작업 기간 동안 데이터베이스 배타 락을 보유합니다. 동일한 데이터베이스에 잠금을 적용한 다른 작업은 해당 작업이 완료될 때까지 차단됩니다. 데이터베이스에 잠금을 적용하는 작업에 관한 내용은 일반적인 클라이언트 작업에서 어떤 잠금을 사용하나요?를 확인하세요.
경고
The convertToCapped will not recreate indexes from the original collection on the new collection, other than the index on the _id field. If you need indexes on this collection you will need to create these indexes after the conversion is complete.
예시
collection 변환
다음 예제에서는 db.collection.insertOne() 를 사용하여 events collection을 만들고 db.collection.stats() 를 사용하여 collection에 대한 정보를 얻습니다.
db.events.insertOne( { click: 'button-1', time: new Date() } ) db.events.stats()
MongoDB는 다음을 반환합니다:
{ "ns" : "test.events", ... "capped" : false, ... }
events collection을 고정 사이즈 컬렉션으로 변환하고 업데이트된 collection 정보를 보려면 다음 명령을 실행합니다.
db.runCommand( { convertToCapped: 'events', size: 8192 } ) db.events.stats()
MongoDB는 다음을 반환합니다:
{ "ns" : "test.events", ... "capped" : true, "max" : Long("9223372036854775807"), "maxSize" : 8192, ... }
The convertToCapped will not recreate indexes from the original collection on the new collection, other than the index on the _id field. If you need indexes on this collection you will need to create these indexes after the conversion is complete.