Docs Menu

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 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하십시오.

db.createView 의 구문은 다음과 같습니다.

db.createView(<view>, <source>, <pipeline>, <collation>)

The method has the following parameters:

Parameter
유형
설명

view

문자열

The name of the view to create.

source

문자열

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.

pipeline

배열

An array that consists of the aggregation pipeline stage(s). db.createView() creates the view by applying the specified pipeline to the source collection or view.

보기 정의 pipeline에는 $out 또는 $merge 단계를 포함할 수 없습니다. 이 제한은 $lookup 단계 또는 $facet 단계에서 사용되는 파이프라인과 같은 임베디드 파이프라인에도 적용됩니다.

뷰 정의는 공개입니다. 즉, 뷰에 대한 db.getCollectionInfos()explain 작업에는 뷰를 정의하는 파이프라인이 포함됩니다. 따라서 뷰 정의에 민감한 필드와 값을 직접 참조하지 않는 것이 좋습니다.

collation

문서

Optional. Specifies the default 데이터 정렬 for the view.

데이터 정렬을 사용하면 대소문자 및 악센트 표시 규칙과 같은 문자열 비교에 대한 언어별 규칙을 지정할 수 있습니다.

If the underlying source is a collection, the view does not inherit the collection's collation settings.

If no collation is specified, the view's default collation is the "simple" binary comparison collator.

If the underlying source is another view, the view must specify the same collation settings.

데이터 정렬 옵션의 구문은 다음과 같습니다:

collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}

데이터 정렬을 지정할 때 locale 필드는 필수이고, 다른 데이터 정렬 필드는 모두 선택 사항입니다. 필드에 대한 설명은 데이터 정렬 문서를 참조하세요.

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 행동.

이 페이지의 내용