ডাটাবেস

বর্ণনা

একটি ডাটাবেসের বিভিন্ন কালেকশন এবং নেস্টেড লেভেল জুড়ে থাকা সমস্ত ডকুমেন্ট ফেরত দেয়।

উদাহরণ

Web

// Count all documents in the database
const results = await execute(db.pipeline()
  .database()
  .aggregate(countAll().as("total"))
  );
সুইফট
// Count all documents in the database
let results = try await db.pipeline()
  .database()
  .aggregate([CountAll().as("total")])
  .execute()

Kotlin

// Count all documents in the database
val results = db.pipeline()
    .database()
    .aggregate(AggregateFunction.countAll().alias("total"))
    .execute()

Java

      // Count all documents in the database
Task<Pipeline.Snapshot> results = db.pipeline()
    .database()
    .aggregate(AggregateFunction.countAll().alias("total"))
    .execute();
    
পাইথন
from google.cloud.firestore_v1.pipeline_expressions import Count

# Count all documents in the database
results = client.pipeline().database().aggregate(Count().as_("total")).execute()
জাভা
// Count all documents in the database
Pipeline.Snapshot results =
    firestore.pipeline().database().aggregate(countAll().as("total")).execute().get();
যান
// Count all documents in the database
snapshot := client.Pipeline().
	Database().
	Aggregate(firestore.Accumulators(firestore.CountAll().As("total"))).
	Execute(ctx)

আচরণ

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

database(...) পর্যায় থেকে প্রাপ্ত ডকুমেন্টগুলোর ক্রম অস্থিতিশীল এবং নির্ভরযোগ্য নয়। একটি সুনির্দিষ্ট ক্রম পাওয়ার জন্য পরবর্তী sort(...) পর্যায় ব্যবহার করা যেতে পারে।

উদাহরণস্বরূপ, নিম্নলিখিত নথিগুলির জন্য:

নোড.জেএস

await db.collection("cities").doc("SF").set({name: "San Francsico", state: "California", population: 800000});
await db.collection("states").doc("CA").set({name: "California", population: 39000000});
await db.collection("countries").doc("USA").set({name: "United States of America", population: 340000000});

database(...) পর্যায়টি ডাটাবেসের সমস্ত ডকুমেন্ট পুনরুদ্ধার করতে ব্যবহার করা যেতে পারে।

নোড.জেএস

const results = await db.pipeline()
  .database()
  .sort(field("population").ascending())
  .execute();

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

  { name: "San Francsico", state: "California", population: 800000 }
  { name: "California", population: 39000000 }
  { name: "United States of America", population: 340000000 }