ब्यौरा
यह फ़ंक्शन, किसी दूसरी पाइपलाइन के दस्तावेज़ों को मौजूदा पाइपलाइन के दस्तावेज़ों के साथ मर्ज करता है.
सिंटैक्स
Node.js
const results = await db.pipeline()
.collection("cities/SF/restaurants")
.union(db.pipeline().collection("cities/NYC/restaurants"))
.execute();
क्लाइंट के उदाहरण
Node.js
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()) );
Swift
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();
Python
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() )
Java
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 का अगला चरण जोड़ा जा सकता है.
Node.js
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();
Python
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() )
Java
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 स्टेज जोड़ा जा सकता है.