데이터베이스 (입력 단계)

설명

다양한 컬렉션과 중첩 수준에 걸쳐 데이터베이스 내의 모든 문서를 반환합니다.

예시

// 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()
자바
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()
자바
// 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 }