Usuwanie pól

Opis

Usuwa 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();
Go
snapshot := client.Pipeline().Collection("cities").
	RemoveFields(firestore.Fields("population", "location.state")).
	Execute(ctx)

Zachowanie

Usuwanie zagnieżdżonych pól

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

Aby na przykład usunąć z zbioru danych zagnieżdżone pole 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();

W wyniku tego powstają 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 w przypadku nieistniejących pól

Jeśli pole zagnieżdżone lub najwyższego poziomu przekazane do funkcji remove_fields(...) nie występuje w dokumencie, etap nie zmodyfikuje dokumentu w przypadku tego pola. Pozostałe istniejące pola nadal będą usuwane.