필드 삭제

설명

이전 단계에서 생성된 문서에서 필드를 삭제합니다.

생성된 문서에는 삭제하도록 지정된 필드를 제외하고 이전 단계의 모든 필드가 포함됩니다.

구문

Node.js

const results = await db.pipeline()
  .collection("/cities")
  .removeFields('population', 'location.state')
  .execute();

클라이언트 예시

Node.js
const results = await db.pipeline()
  .collection("cities")
  .removeFields("population", "location.state")
  .execute();

Web

const results = await execute(db.pipeline()
  .collection("cities")
  .removeFields("population", "location.state"));
Swift
let results = try await db.pipeline()
  .collection("cities")
  .removeFields(["population", "location.state"])
  .execute()

Kotlin

val results = db.pipeline()
    .collection("cities")
    .removeFields("population", "location.state")
    .execute()

Java

Task<Pipeline.Snapshot> results = db.pipeline()
        .collection("cities")
        .removeFields("population", "location.state")
        .execute();
Python
results = (
    client.pipeline()
    .collection("cities")
    .remove_fields("population", "location.state")
    .execute()
)
자바
Pipeline.Snapshot results =
    firestore
        .pipeline()
        .collection("cities")
        .removeFields("population", "location.state")
        .execute()
        .get();

동작

중첩 필드 삭제

remove_fields 단계에서는 중첩 필드 구문을 따르며 맵에서 키를 삭제합니다.

예를 들어 데이터 세트에서 중첩 state 필드를 삭제하려면 다음을 실행합니다.

Node.js

await db.collection('cities').doc('SF').set({name: 'San Francisco', location: {country: 'USA', state: 'California'}});
await db.collection('cities').doc('TO').set({name: 'Toronto', location: {country: 'Canada', province: 'Ontario'}});

다음 파이프라인을 사용할 수 있습니다.

Node.js

const results = await db.pipeline()
  .collection("/cities")
  .removeFields('location.state')
  .execute();

그러면 다음과 같은 문서가 생성됩니다.

{name: 'San Francisco', location: {country: 'USA'}}
{name: 'Toronto', location: {country: 'Canada', province: 'Ontario'}}

배열 내 요소 삭제는 지원되지 않습니다.

존재하지 않는 필드 삭제

remove_fields에 지정된 중첩 필드 또는 최상위 필드가 문서에 없으면 단계에서 해당 필드의 문서를 수정하지 않습니다. 기존의 다른 필드는 계속 삭제됩니다.