Dokümanlar

Açıklama

Önceden tanımlanmış sabit bir belge kümesine bakarak belgeleri döndürür.

Aşama, giriş olarak bir veya daha fazla belge almalı ve aynı yola sahip belgeler içermemelidir. Referans verilen bir doküman yoksa bu doküman yolu için sonuç üretilmez.

Bu aşama, Cloud Firestore'nın batchGet aşamasına benzer şekilde çalışır ve toplu işlemden sonra filtreleme sonrası adımlarını uygulamak yerine sonuçları doğrudan filtrelemenize olanak tanır.

Örnekler

Web

const results = await execute(db.pipeline()
  .documents([
    doc(db, "cities", "SF"),
    doc(db, "cities", "DC"),
    doc(db, "cities", "NY")
  ])
);
Swift
let results = try await db.pipeline()
  .documents([
    db.collection("cities").document("SF"),
    db.collection("cities").document("DC"),
    db.collection("cities").document("NY")
  ]).execute()

Kotlin

val results = db.pipeline()
    .documents(
        db.collection("cities").document("SF"),
        db.collection("cities").document("DC"),
        db.collection("cities").document("NY")
    ).execute()

Java

      Task<Pipeline.Snapshot> results = db.pipeline()
    .documents(
        db.collection("cities").document("SF"),
        db.collection("cities").document("DC"),
        db.collection("cities").document("NY")
    ).execute();
    
Python
results = (
    client.pipeline()
    .documents(
        client.collection("cities").document("SF"),
        client.collection("cities").document("DC"),
        client.collection("cities").document("NY"),
    )
    .execute()
)
Java
Pipeline.Snapshot results =
    firestore
        .pipeline()
        .documents(
            firestore.collection("cities").document("SF"),
            firestore.collection("cities").document("DC"),
            firestore.collection("cities").document("NY"))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Documents([]*firestore.DocumentRef{
		client.Collection("cities").Doc("SF"),
		client.Collection("cities").Doc("DC"),
		client.Collection("cities").Doc("NY"),
	}).
	Execute(ctx)

Davranış

documents(...) aşamasını kullanmak için bu aşama, ardışık düzende ilk aşama olarak görünmelidir.

documents(...) aşamasından döndürülen belgelerin sırası kararsızdır ve güvenilir değildir. Sonraki bir sort(...) aşaması, deterministik bir sıralama elde etmek için kullanılabilir.

Örneğin, aşağıdaki belgeler için:

Node.js

await db.collection("cities").doc("SF").set({name: "San Francsico", state: "California"});
await db.collection("cities").doc("NYC").set({name: "New York City", state: "New York"});
await db.collection("cities").doc("CHI").set({name: "Chicago", state: "Illinois"});

documents(...) aşaması yalnızca SF ve NYC dokümanlarını almak ve bunları ada göre artan sırada sıralamak için kullanılabilir.

Node.js

const results = await db.pipeline()
  .documents(
    db.collection("cities").doc("SF"),
    db.collection("cities").doc("NYC"))
  .sort(field("name").ascending())
  .execute();

Bu sorgu aşağıdaki belgeleri oluşturur:

  { name: "New York City", state: "New York" }
  { name: "San Francsico", state: "California" }