কালেকশন গ্রুপ

বিবরণ

নির্দিষ্ট কালেকশন আইডি সহ যেকোনও কালেকশন থেকে সব ডকুমেন্ট দেখায়, এর পেরেন্ট যাই হোক না কেন।

উদাহরণ

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();
    
Python
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();
Go
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 }