문서 메뉴
문서 홈
/ / /
몽고이드
/

collection 구성

이 페이지의 내용

  • 문서 collection 구성하기
  • Time Series 컬렉션
  • 고정 사이즈 컬렉션
  • 컬렉션에 기본값 데이터 정렬을 설정하다
  • collection 관리 레이크 작업

store_in 매크로를 사용하여 문서에 대한 collection 옵션을 지정할 수 있습니다. 이 매크로는 드라이버에서 지원하는 모든 collection 옵션을 포함할 수 있는 :collection_options 인수를 허용합니다.

참고

옵션을 적용하려면 컬렉션을 명시적으로 먼저 생성해야 합니다. 이 작업은 컬렉션 관리 레이크 작업을 사용하여 수행해야 합니다.

컬렉션 옵션에 대한 자세한 내용은 드라이버 컬렉션 페이지 를 참조하세요.

참고

collection 옵션은 드라이버 버전과 MongoDB Server 버전에 따라 다릅니다. time-series 컬렉션과 같은 일부 옵션은 이전 서버 버전에서 사용하지 못할 수 있습니다.

class Measurement
include Mongoid::Document
field :temperature, type: Integer
field :timestamp, type: Time
store_in collection_options: {
time_series: {
timeField: "timestamp",
granularity: "minutes"
},
expire_after: 604800
}
end
class Name
include Mongoid::Document
store_in collection_options: {
capped: true,
size: 1024
}
end
class Name
include Mongoid::Document
store_in collection_options: {
collation: {
locale: 'fr'
}
}
end

문서에 대한 collection 옵션을 지정하는 경우 사용하기 전에 해당 collection을 명시적으로 생성해야 합니다. 이렇게 하려면 제공된 db:mongoid:create_collections 레이크 작업을 사용합니다.

$ rake db:mongoid:create_collections

create collection 명령은 Rails 콘솔에서 실행하여 하나의 모델에 대해서만 작동합니다.

# Create collection for Model
Model.create_collection

돌아가기

유효성 검사