AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.
Docs Menu

convertToCapped(데이터베이스 명령)

convertToCapped

경고

샤드 컬렉션에서는 이 명령을 실행하지 않음

MongoDB does not support the convertToCapped command on sharded collections.

The convertToCapped command converts an existing, non-capped collection to a capped collection within the same database.

이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.

  • MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스

명령은 다음과 같은 구문을 가집니다:

db.runCommand(
{
convertToCapped: <collection>,
size: <capped size>,
writeConcern: <document>,
comment: <any>
}
)

이 명령은 다음 필드를 사용합니다.

필드
설명

convertToCapped (영문)

변환할 기존 컬렉션의 이름입니다.

size

고정 사이즈 컬렉션의 최대 크기(단위: 바이트)입니다.

쓰기 고려

선택 사항. 명령의 쓰기 고려 drop (write concern) 를 Express하는 문서입니다. 기본 쓰기 고려 (write concern)를 사용하려면 생략합니다.

comment

선택 사항. 이 명령에 첨부할 사용자 제공 코멘트입니다. 설정되면 이 설명은 다음 위치에서 이 명령의 레코드와 함께 표시됩니다.

댓글은 유효한 모든 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.

다음 예제에서는 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.

이 페이지 평가하기

이 페이지의 내용