db.createView()
db.createView()
참고
명확화
This page discusses standard views. For discussion of on-demand materialized views, see 온디맨드 구체화된 보기.
To understand the differences between the view types, see Comparison with On-Demand Materialized Views.
Creates a view as the result of the applying the specified 집계 파이프라인 to the source collection or view. Views act as read-only collections, and are computed on demand during read operations. You must create views in the same database as the source collection. MongoDB executes read operations on views as part of the underlying aggregation pipeline.
보기 정의
pipeline
에는$out
또는$merge
단계를 포함할 수 없습니다. 이 제한은$lookup
단계 또는$facet
단계에서 사용되는 파이프라인과 같은 임베디드 파이프라인에도 적용됩니다.
호환성
이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
참고
이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하십시오.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
구문
db.createView
의 구문은 다음과 같습니다.
db.createView(<view>, <source>, <pipeline>, <collation>)
The method has the following parameters:
Parameter | 유형 | 설명 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| 문자열 | The name of the view to create. | ||||||||||
| 문자열 | The name of the source collection or view from which to create the view. The name does not include the database name and implies the same database as the view to create; it is not the full namespace of the collection or view. You must create views in the same database as the source collection. | ||||||||||
| 배열 | An array that consists of the aggregation pipeline stage(s). 보기 정의 뷰 정의는 공개입니다. 즉, 뷰에 대한 | ||||||||||
| 문서 | Optional. Specifies the default 데이터 정렬 for the view. 데이터 정렬을 사용하면 대소문자 및 악센트 표시 규칙과 같은 문자열 비교에 대한 언어별 규칙을 지정할 수 있습니다. If the underlying If no collation is specified, the view's default collation is the "simple" binary comparison collator. If the underlying 데이터 정렬 옵션의 구문은 다음과 같습니다:
데이터 정렬을 지정할 때 |
The db.createView()
method wraps the following
create
command operation:
db.runCommand( { create: <view>, viewOn: <source>, pipeline: <pipeline>, collation: <collation> } )
중요
View Names are Included in Collection List Output
Operations that list collections, such as
db.getCollectionInfos()
and db.getCollectionNames()
,
include views in their outputs.
뷰 정의는 공개입니다. 즉, 뷰에 대한 db.getCollectionInfos()
및 explain
작업에는 뷰를 정의하는 파이프라인이 포함됩니다. 따라서 뷰 정의에 민감한 필드와 값을 직접 참조하지 않는 것이 좋습니다.
예시
To see examples of creating a view, see the following pages:
행동
To see behavioral details of views, see 행동.