সংগ্রহ

বিবরণ

প্রদত্ত সংগ্রহ থেকে সমস্ত ডকুমেন্ট দেখায়। কালেকশন নেস্ট করা যাবে।

উদাহরণ

Web

const results = await execute(db.pipeline()
  .collection("users/bob/games")
  .sort(field("name").ascending())
  );
Swift
let results = try await db.pipeline()
  .collection("users/bob/games")
  .sort([Field("name").ascending()])
  .execute()

Kotlin

val results = db.pipeline()
    .collection("users/bob/games")
    .sort(field("name").ascending())
    .execute()

Java

Task<Pipeline.Snapshot> results = db.pipeline()
    .collection("users/bob/games")
    .sort(field("name").ascending())
    .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field

results = (
    client.pipeline()
    .collection("users/bob/games")
    .sort(Field.of("name").ascending())
    .execute()
)
জাভা
Pipeline.Snapshot results =
    firestore
        .pipeline()
        .collection("users/bob/games")
        .sort(ascending(field("name")))
        .execute()
        .get();
Go
snapshot := client.Pipeline().
	Collection("users/bob/games").
	Sort(firestore.Orders(firestore.Ascending(firestore.FieldOf("name")))).
	Execute(ctx)

আচরণ

collection(...) স্টেজ ব্যবহার করতে হলে, এটিকে পাইপলাইনে (বা সাব-পাইপলাইনে) প্রথম স্টেজ হিসেবে দেখাতে হবে।

collection(...) স্টেজ থেকে ফেরত আসা ডকুমেন্টের ক্রম পরিবর্তনশীল এবং তার উপর নির্ভর করা যায় না। Cloud Firestore সবচেয়ে দক্ষ উপায়ে কোয়েরি এক্সিকিউট করার চেষ্টা করবে, যা স্কিমা বা ইন্ডেক্স কনফিগারেশনের উপর নির্ভর করে ক্রম পরিবর্তন করতে পারে। একটি নির্ধারক ক্রম পেতে পরবর্তী sort(...) স্টেজ ব্যবহার করা যেতে পারে।

যেমন, নিম্নলিখিত ডকুমেন্টের জন্য:

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"});
await db.collection("states").doc("CA").set({name: "California"});

collection স্টেজ ব্যবহার করে cities কালেকশনের সব শহরের নাম ফিরিয়ে আনা এবং সেগুলিকে নামের ক্রমানুসারে সাজানো যেতে পারে।

Node.js

const results = await db.pipeline()
  .collection("/cities")
  .sort(field("name").ascending())
  .execute();

এই কোয়েরি নিম্নলিখিত ডকুমেন্ট তৈরি করে:

  { name: "Chicago", state: "Illinois" }
  { name: "New York City", state: "New York" }
  { name: "San Francisco", state: "California" }

সাবকালেকশন

collection(...) স্টেজটি নির্দিষ্ট পেরেন্টের অধীনে থাকা কালেকশন টার্গেট করতেও ব্যবহার করা যেতে পারে, এর জন্য স্টেজের সম্পূর্ণ পাথ প্রদান করতে হবে।

যেমন, নিম্নলিখিত ডকুমেন্টের জন্য:

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});

এই উদাহরণের জন্য, আমরা শুধু নিউ ইয়র্ক শহরের বিভাগগুলি চাই।

Node.js

const results = await db.pipeline()
  .collection("/cities/NY/departments")
  .sort(field("employees").ascending())
  .execute();

এটি সম্পূর্ণ পাথ cities/NY/departments-এর অধীনে থাকা সব বিভাগ দেখাবে।

  { name: "NY Building Deparment", employees: 1000 }
  { name: "NY Finance Deparment", employees: 1200 }