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

$redact (집계 단계)

$redact

문서 자체에 저장된 정보를 기반으로 전체 문서 또는 문서 내 컨텐츠가 출력되지 않도록 제한합니다.

미들웨어와 편집이 탑재된 보안 아키텍처 다이어그램.

The $redact stage has the following prototype form:

{ $redact: <expression> }

인수는 $$DESCEND, $$PRUNE 또는 $$KEEP 시스템 변수로 해석되는 한 유효한 표현식 이 될 수 있습니다. 표현식에 대한 자세한 내용은 표현식을 참조하세요 .

시스템 변수
설명

$redact returns the fields at the current document level, excluding embedded documents. To include embedded documents and embedded documents within arrays, apply the $cond expression to the embedded documents to determine access for these embedded documents.

$redact excludes all fields at this current document/embedded document level, without further inspection of any of the excluded fields. This applies even if the excluded field contains embedded documents that may have different access levels.

$redact returns or keeps all fields at this current document/embedded document level, without further inspection of the fields at this level. This applies even if the included field contains embedded documents that may have different access levels.

이 섹션의 예시에서는 db.collection.aggregate() 헬퍼를 사용합니다.

forecasts collection에는 다음 형식의 문서가 포함되어 있습니다. 여기서 tags 필드는 해당 문서/내장된 문서 수준에 대한 다양한 액세스 값을 나열합니다. 즉, [ "G", "STLW" ] 값은 "G" 또는 "STLW"이(가) 데이터에 액세스할 수 있음을 지정합니다.

db.forecasts.insertOne(
{
_id: 1,
title: "123 Department Report",
tags: [ "G", "STLW" ],
year: 2014,
subsections: [
{
subtitle: "Section 1: Overview",
tags: [ "SI", "G" ],
content: "Section 1: This is the content of section 1."
},
{
subtitle: "Section 2: Analysis",
tags: [ "STLW" ],
content: "Section 2: This is the content of section 2."
},
{
subtitle: "Section 3: Budgeting",
tags: [ "TK" ],
content: {
text: "Section 3: This is the content of section 3.",
tags: [ "HCS" ]
}
}
]
}
)

A user has access to view information with either the tag "STLW" or "G". To run a query on all documents with year 2014 for this user, include a $redact stage as in the following:

var userAccess = [ "STLW", "G" ];
db.forecasts.aggregate(
[
{ $match: { year: 2014 } },
{ $redact: {
$cond: {
if: { $gt: [ { $size: { $setIntersection: [ "$tags", userAccess ] } }, 0 ] },
then: "$$DESCEND",
else: "$$PRUNE"
}
}
}
]
);

집계 작업은 다음과 같은 '수정된' 문서를 반환합니다.

{
_id: 1,
title: "123 Department Report",
tags: [ "G", "STLW" ],
year: 2014,
subsections: [
{
subtitle: "Section 1: Overview",
tags: [ "SI", "G" ],
content: "Section 1: This is the content of section 1."
},
{
subtitle: "Section 2: Analysis",
tags: [ "STLW" ],
content : "Section 2: This is the content of section 2."
}
]
}

컬렉션 accounts에는 다음 문서가 포함되어 있습니다.

db.accounts.insertOne(
{
_id: 1,
level: 1,
acct_id: "xyz123",
cc: {
level: 5,
type: "yy",
num: 000000000000,
exp_date: ISODate("2015-11-01T00:00:00.000Z"),
billing_addr: {
level: 5,
addr1: "123 ABC Street",
city: "Some City"
},
shipping_addr: [
{
level: 3,
addr1: "987 XYZ Ave",
city: "Some City"
},
{
level: 3,
addr1: "PO Box 0123",
city: "Some City"
}
]
},
status: "A"
}
)

이 예시 문서에서 level 필드는 데이터를 보는 데 필요한 액세스 수준을 결정합니다.

상태가 A 인 모든 문서에 대해 쿼리를 실행하고 5 수준의 문서/내장된 문서에 포함된 모든 필드를 제외하려면 then 필드에 시스템 변수 "$$PRUNE"을 지정하는 $redact 단계를 포함합니다.

db.accounts.aggregate(
[
{ $match: { status: "A" } },
{
$redact: {
$cond: {
if: { $eq: [ "$level", 5 ] },
then: "$$PRUNE",
else: "$$DESCEND"
}
}
}
]
);

The $redact stage evaluates the level field to determine access. If the level field equals 5, then exclude all fields at that level, even if the excluded field contains embedded documents that may have different level values, such as the shipping_addr field.

집계 작업은 다음과 같은 '수정된' 문서를 반환합니다.

{
_id: 1,
level: 1,
acct_id: "xyz123",
status: "A"
}

The result set shows that the $redact stage excluded the field cc as a whole, including the shipping_addr field which contained embedded documents that had level field values equal to 3 and not 5.

팁

필드 수준 편집을 구현하여 동일한 데이터에 대한 여러 가지 액세스 조합을 설정하는 단계를 수행합니다.

이 가이드 의 시스템 변수에 대해 자세히 학습하려면 애그리게이션 변수 페이지를 참조하세요.

이 페이지 평가하기

이 페이지의 내용