বর্ণনা
অন্য একটি পাইপলাইন থেকে নথিগুলোকে বর্তমান পাইপলাইনের নথিগুলোর সাথে একত্রিত করে।
উদাহরণ
নোড.জেএস
const results = await db.pipeline() .collection("cities/SF/restaurants") .where(eq("type", "chinese")) .union(db.pipeline() .collection("cities/NYC/restaurants") .where(eq("type", "italian"))) .where(gte("rating", 4.5)) .execute();
Web
const results = await execute(db.pipeline() .collection("cities/SF/restaurants") .where(field("type").equal("Chinese")) .union(db.pipeline() .collection("cities/NY/restaurants") .where(field("type").equal("Italian"))) .where(field("rating").greaterThanOrEqual(4.5)) .sort(field("__name__").descending()) );
সুইফট
let results = try await db.pipeline() .collection("cities/SF/restaurants") .where(Field("type").equal("Chinese")) .union(with: db.pipeline() .collection("cities/NY/restaurants") .where(Field("type").equal("Italian"))) .where(Field("rating").greaterThanOrEqual(4.5)) .sort([Field("__name__").descending()]) .execute()
Kotlin
val results = db.pipeline() .collection("cities/SF/restaurants") .where(field("type").equal("Chinese")) .union(db.pipeline() .collection("cities/NY/restaurants") .where(field("type").equal("Italian"))) .where(field("rating").greaterThanOrEqual(4.5)) .sort(field("__name__").descending()) .execute()
Java
Task<Pipeline.Snapshot> results = db.pipeline() .collection("cities/SF/restaurants") .where(field("type").equal("Chinese")) .union(db.pipeline() .collection("cities/NY/restaurants") .where(field("type").equal("Italian"))) .where(field("rating").greaterThanOrEqual(4.5)) .sort(field("__name__").descending()) .execute();
পাইথন
from google.cloud.firestore_v1.pipeline_expressions import Field results = ( client.pipeline() .collection("cities/SF/restaurants") .where(Field.of("type").equal("Chinese")) .union( client.pipeline() .collection("cities/NY/restaurants") .where(Field.of("type").equal("Italian")) ) .where(Field.of("rating").greater_than_or_equal(4.5)) .sort(Field.of("__name__").descending()) .execute() )
জাভা
Pipeline.Snapshot results = firestore .pipeline() .collection("cities/SF/restaurants") .where(field("type").equal("Chinese")) .union( firestore .pipeline() .collection("cities/NY/restaurants") .where(field("type").equal("Italian"))) .where(field("rating").greaterThanOrEqual(4.5)) .sort(descending(field("__name__"))) .execute() .get();
আচরণ
এই পর্যায়ে একাধিক পাইপলাইন সমান্তরালভাবে চালানো হয় এবং ফলাফলগুলোকে একত্রিত করা হয়।
ফলাফলের অনির্ধারিত ক্রম
দুটি পাইপলাইনের মধ্যে ফলাফল একত্রিত করার ক্রম অনির্দিষ্ট। যেকোনো অনুভূত ক্রমই অস্থিতিশীল এবং এর উপর নির্ভর করা উচিত নয়। যদি একটি স্থিতিশীল ক্রমের প্রয়োজন হয়, তবে একটি পরবর্তী sort(...) পর্যায় যোগ করা যেতে পারে।
নোড.জেএস
const results = await db.pipeline() .collection("cities/SF/restaurants") .where(eq("type", "chinese")) .union(db.pipeline() .collection("cities/NYC/restaurants") .where(eq("type", "italian"))) .where(gte("rating", 4.5)) .sort(Field.of("__name__")) .execute();
Kotlin
val results = db.pipeline() .collection("cities/SF/restaurants") .where(field("type").equal("Chinese")) .union(db.pipeline() .collection("cities/NY/restaurants") .where(field("type").equal("Italian"))) .where(field("rating").greaterThanOrEqual(4.5)) .sort(field("__name__").descending()) .execute()
Java
Task<Pipeline.Snapshot> results = db.pipeline() .collection("cities/SF/restaurants") .where(field("type").equal("Chinese")) .union(db.pipeline() .collection("cities/NY/restaurants") .where(field("type").equal("Italian"))) .where(field("rating").greaterThanOrEqual(4.5)) .sort(field("__name__").descending()) .execute();
পাইথন
from google.cloud.firestore_v1.pipeline_expressions import Field results = ( client.pipeline() .collection("cities/SF/restaurants") .where(Field.of("type").equal("Chinese")) .union( client.pipeline() .collection("cities/NY/restaurants") .where(Field.of("type").equal("Italian")) ) .where(Field.of("rating").greater_than_or_equal(4.5)) .sort(Field.of("__name__").descending()) .execute() )
জাভা
Pipeline.Snapshot results = firestore .pipeline() .collection("cities/SF/restaurants") .where(field("type").equal("Chinese")) .union( firestore .pipeline() .collection("cities/NY/restaurants") .where(field("type").equal("Italian"))) .where(field("rating").greaterThanOrEqual(4.5)) .sort(descending(field("__name__"))) .execute() .get();
ডুপ্লিকেট ফলাফল
union(...) পর্যায়টি ফলাফলের পুনরাবৃত্তি দূর করে না। যদি পুনরাবৃত্তিমূলক ফলাফল অপসারণ করার প্রয়োজন হয়, তবে এর পরে distinct(...) বা aggregate(...) পর্যায় যোগ করা যেতে পারে।