Usuwanie pól

Opis

Usuń pola z dokumentów wygenerowanych na poprzednim etapie.

Wygenerowane dokumenty będą zawierać wszystkie pola z poprzedniego etapu z wyjątkiem pól, które mają zostać usunięte.

Przykłady

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()
)
Java
Pipeline.Snapshot results =
    firestore
        .pipeline()
        .collection("cities")
        .removeFields("population", "location.state")
        .execute()
        .get();

Zachowanie

Usuwanie pól zagnieżdżonych

Etap remove_fields(...) uwzględnia składnię pól zagnieżdżonych i usuwa klucze z mapy.

Aby na przykład usunąć zbiór danych zagnieżdżonego pola stanu:

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"}});

Możesz użyć tego potoku:

Node.js

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

Który generuje te dokumenty:

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

Usuwanie elementów z tablicy nie jest obsługiwane.

Usuwanie pól nieistniejących

Jeśli pole zagnieżdżone lub najwyższego poziomu przekazane do remove_fields(...) nie istnieje w dokumencie, etap nie będzie edytować dokumentu w przypadku tego pola. Pozostałe istniejące pola zostaną usunięte.