Şununla değiştir:

Açıklama

Mevcut dokümandaki alanları, belirli bir ifadedeki alanlarla değiştirir.

İfade, değişmez bir harita veya harita olarak değerlendirilen bir ifade olabilir. Belirli bir ifade harita olarak değerlendirilmezse bu aşamada hata döndürülür.

Desteklenen 3 mod vardır:

  • full_replace: Belgenin tamamını, verilen ifadenin sonucuyla değiştirir ve bu sonuçta görünmeyen alanları atlar.
  • merge_overwrite_existing: İfadeyi mevcut belgeyle birleştirir ve belgedeki alan değerlerinin üzerine ifadedeki değerleri yazar.
  • merge_keep_existing: İfadeyi mevcut belgeyle birleştirir ve yalnızca belgede alan değeri yoksa alan değerlerini ekler.

Örnekler

Aşağıdaki belgeleri içeren bir cities koleksiyonu oluşturun:

Node.js

await db.collection("cities").doc("SF").set({name: "San Francisco", population: 800000, location: {country: "USA", state: "California"}});
await db.collection("cities").doc("TO").set({name: "Toronto", population:  3000000, province: "ON", location: {country: "Canada", province: "Ontario"}});
await db.collection("cities").doc("NY").set({name: "New York", location: {country: "USA", state: "New York"}});
await db.collection("cities").cov("AT").set({name: "Atlantis", population: null});

Dokümanın değiştirilmiş bir sürümünü almak için full_replace modunu kullanma

İç içe yerleştirilmiş location alanını diğer tüm verileri atarak ayıklayın:

Node.js
  const names = await db.pipeline()
    .collection("/cities")
    .replace_with(Field.of("location"), "full_replace")
    .execute();
    
Java
Pipeline.Snapshot names =
    firestore.pipeline().collection("cities").replaceWith(field("location")).execute().get();
Go
snapshot := client.Pipeline().
	Collection("cities").
	ReplaceWith(firestore.FieldOf("location")).
	Execute(ctx)

Bu işlem sonucunda aşağıdaki belgeler oluşturulur:

{ country: "USA", state: "California" },
{ country: "Canada", province: "Ontario" },
{ country: "USA", state: "New York" },
{ }

Alanları ayarlamak için merge_overwrite_existing modunu kullanma

Tüm dokümanların population alanını 0 olarak ayarlayarak mevcut değerlerin üzerine yazın:

Node.js
  const censoredResults = await db.pipeline()
    .collection("/cities")
    .replace_with(map("population", 0), "merge_overwrite_existing")
    .execute();
    

Bu işlem sonucunda aşağıdaki belgeler oluşturulur:

{name: "San Francisco", population: 0, location: {country: "USA", state: "California"}},
{name: "Toronto", population: 0, province: "ON", location: {country: "Canada", province: "Ontario"}},
{name: "New York", population: 0, location: {country: "USA", state: "New York"}},
{name: "Atlantis", population: 0}

Varsayılan değer eklemek için merge_keep_existing modunu kullanma

Bir dokümanda görünmediğinde location için varsayılan değer ayarlama:

Node.js
  const defaultedResults = await db.pipeline()
    .collection("/cities")
    .replace_with(map("location", "unknown"), "merge_keep_existing")
    .execute();
    

Bu işlem sonucunda aşağıdaki belgeler oluşturulur:

{ name: "San Francisco", population: 800000, location: { country: "USA", state: "California" } },
{ name: "Toronto", province: "ON", population: 3000000, location: { country: "Canada", province: "Ontario" } },
{ name: "New York", location: { country: "USA", state: "New York" } },
{ name: "Atlantis", population: null, location: "unknown" }