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

$unset (집계 단계)

참고

명확화

The following page refers to the aggregation stage $unset. For the update operator $unset, see $unset.

$unset

문서에서 필드를 제거/제외합니다.

The $unset stage has the following syntax:

  • To remove a single field, the $unset takes a string that specifies the field to remove:

    { $unset: "<field>" }
  • To remove multiple fields, the $unset takes an array of fields to remove.

    { $unset: [ "<field1>", "<field2>", ... ] }

The $unset is an alias for the $project stage that removes/excludes fields:

{ $project: { "<field1>": 0, "<field2>": 0, ... } }

내장된 문서 내에서 필드를 제거하거나 제외하려면 다음과 같이 점 표기법을 사용하면 됩니다.

{ $unset: "<field.nestedfield>" }

or

{ $unset: [ "<field1.nestedfield>", ...] }

다음 문서로 샘플 books 컬렉션을 생성합니다.

db.books.insertMany([
{ "_id" : 1, title: "Antelope Antics", isbn: "0001122223334", author: { last:"An", first: "Auntie" }, copies: [ { warehouse: "A", qty: 5 }, { warehouse: "B", qty: 15 } ] },
{ "_id" : 2, title: "Bees Babble", isbn: "999999999333", author: { last:"Bumble", first: "Bee" }, copies: [ { warehouse: "A", qty: 2 }, { warehouse: "B", qty: 5 } ] }
])

다음 예에서는 최상위 필드 copies를 제거합니다.

db.books.aggregate([ { $unset: "copies" } ])

또는 다음 구문을 사용할 수도 있습니다.

db.books.aggregate([ { $unset: [ "copies" ] } ])

두 작업 모두 다음 문서를 반환합니다.

{ "_id" : 1, "title" : "Antelope Antics", "isbn" : "0001122223334", "author" : { "last" : "An", "first" : "Auntie" } }
{ "_id" : 2, "title" : "Bees Babble", "isbn" : "999999999333", "author" : { "last" : "Bumble", "first" : "Bee" } }

다음 예에서는 최상위 필드 isbn 및 copies를 제거합니다.

db.books.aggregate([
{ $unset: [ "isbn", "copies" ] }
])

The $unset operation outputs the following documents:

{ "_id" : 1, "title" : "Antelope Antics", "author" : { "last" : "An", "first" : "Auntie" } }
{ "_id" : 2, "title" : "Bees Babble", "author" : { "last" : "Bumble", "first" : "Bee" } }

다음 예시에서는 최상위 필드 isbn, 내장된 필드를 first (name 문서에서) 제거하고 및 내장된 필드 warehouse를(copies 배열의 요소에서) 제거합니다.

db.books.aggregate([
{ $unset: [ "isbn", "author.first", "copies.warehouse" ] }
])

The $unset operation outputs the following documents:

{ "_id" : 1, "title" : "Antelope Antics", "author" : { "last" : "An" }, "copies" : [ { "qty" : 5 }, { "qty" : 15 } ] }
{ "_id" : 2, "title" : "Bees Babble", "author" : { "last" : "Bumble" }, "copies" : [ { "qty" : 2 }, { "qty" : 5 } ] }
이 페이지 평가하기

이 페이지의 내용