データベース(入力ステージ)

説明

さまざまなコレクションとネストレベルに配置された、データベース内のすべてのドキュメントを返します。

ウェブ

// 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
Android
// Count all documents in the database
val results = db.pipeline()
    .database()
    .aggregate(AggregateFunction.countAll().alias("total"))
    .execute()
Java
Android
      // 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();

動作

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 }