شرح
همه اسناد را از هر مجموعهای با شناسه مجموعه مشخصشده برمیگرداند، بدون توجه به والد آن.
مثالها
Web
const results = await execute(db.pipeline() .collectionGroup("games") .sort(field("name").ascending()) );
Swift
let results = try await db.pipeline() .collectionGroup("games") .sort([Field("name").ascending()]) .execute()
Kotlin
val results = db.pipeline() .collectionGroup("games") .sort(field("name").ascending()) .execute()
Java
Task<Pipeline.Snapshot> results = db.pipeline() .collectionGroup("games") .sort(field("name").ascending()) .execute();
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field results = ( client.pipeline() .collection_group("games") .sort(Field.of("name").ascending()) .execute() )
جاوا
Pipeline.Snapshot results = firestore .pipeline() .collectionGroup("games") .sort(ascending(field("name"))) .execute() .get();
رفتن
snapshot := client.Pipeline(). CollectionGroup("games"). Sort(firestore.Orders(firestore.Ascending(firestore.FieldOf("name")))). Execute(ctx)
رفتار
برای استفاده از مرحله collection_group(...)، این مرحله باید بهعنوان اولین مرحله در خط لوله ظاهر شود.
ترتیب اسناد برگشتی از مرحله collection_group(...) ناپایدار است و نمیتوان به آن اعتماد کرد. Cloud Firestore تلاش میکند پُرسمان را به کارآمدترین روش ممکن اجرا کند، که میتواند ترتیب را بسته به طرحواره یا پیکربندی نمایه تغییر دهد. از مرحله بعدی
sort(...) میتوان برای بهدست آوردن ترتیب قطعی
استفاده کرد.
برای مثال، برای اسناد زیر:
Node.js
await db.collection("cities/SF/departments").doc("building").set({name: "SF Building Deparment", employees: 750});
await db.collection("cities/NY/departments").doc("building").set({name: "NY Building Deparment", employees: 1000});
await db.collection("cities/CHI/departments").doc("building").set({name: "CHI Building Deparment", employees: 900});
await db.collection("cities/NY/departments").doc("finance").set({name: "NY Finance Deparment", employees: 1200});
از مرحله collection_group(...) میتوان برای برگرداندن اسناد از هر مجموعه
بخش در همه مجموعههای والد در پایگاه داده استفاده کرد.
Node.js
const results = await db.pipeline()
.collectionGroup("departments")
.sort(field("employees").ascending())
.execute();
این پُرسمان اسناد زیر را تولید میکند:
{ name: "SF Building Deparment", employees: 750 }
{ name: "CHI Building Deparment", employees: 900 }
{ name: "NY Building Deparment", employees: 1000 }
{ name: "NY Finance Deparment", employees: 1200 }