설명
상위 요소에 관계없이 지정된 컬렉션 ID가 있는 모든 컬렉션의 모든 문서를 반환합니다.
구문
Node.js
const results = await db.pipeline()
.collectionGroup('departments')
.execute();
클라이언트 예시
Web
const results = await execute(db.pipeline() .collectionGroup("games") .sort(field("name").ascending()) );
Swift
let results = try await db.pipeline() .collectionGroup("games") .sort([Field("name").ascending()]) .execute()
Kotlin
val results = db.pipeline() .collectionGroup("games") .sort(field("name").ascending()) .execute()
Java
Task<Pipeline.Snapshot> results = db.pipeline() .collectionGroup("games") .sort(field("name").ascending()) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field results = ( client.pipeline() .collection_group("games") .sort(Field.of("name").ascending()) .execute() )
자바
Pipeline.Snapshot results = firestore .pipeline() .collectionGroup("games") .sort(ascending(field("name"))) .execute() .get();
동작
collection_group 단계를 사용하려면 파이프라인의 첫 번째 단계로 표시되어야 합니다.
collection_group 단계에서 반환되는 문서의 순서는 불안정하므로 이에 의존해서는 안 됩니다. 후속 정렬 단계를 사용하여 결정적 순서를 가져올 수 있습니다.
예를 들어 다음 문서의 경우:
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});
collection_group 단계를 사용하여 데이터베이스의 모든 상위 컬렉션에 있는 모든 departments 컬렉션에서 문서를 반환할 수 있습니다.
Node.js
const results = await db.pipeline()
.collectionGroup('departments')
.sort(field('employees').ascending())
.execute();
이 쿼리는 다음과 같은 문서를 생성합니다.
{name: 'SF Building Deparment', employees: 750}
{name: 'CHI Building Deparment', employees: 900}
{name: 'NY Building Deparment', employees: 1000}
{name: 'NY Finance Deparment', employees: 1200}