डेटाबेस

ब्यौरा

यह फ़ंक्शन, अलग-अलग कलेक्शन और नेस्ट किए गए लेवल में मौजूद किसी डेटाबेस के सभी दस्तावेज़ दिखाता है.

उदाहरण

Web

// Count all documents in the database
const results = await execute(db.pipeline()
  .database()
  .aggregate(countAll().as("total"))
  );
Swift
// 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();
    
Python
from google.cloud.firestore_v1.pipeline_expressions import Count

# Count all documents in the database
results = client.pipeline().database().aggregate(Count().as_("total")).execute()
Java
// 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(...) स्टेज का इस्तेमाल किया जा सकता है.

उदाहरण के लिए, इन दस्तावेज़ों के लिए:

Node.js

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(...) स्टेज का इस्तेमाल, डेटाबेस में मौजूद सभी दस्तावेज़ों को वापस पाने के लिए किया जा सकता है.

Node.js

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 }