new QueryPartition
()
A split point that can be used in a query as a starting and/or end point for
the query results. The cursors returned by #startAt and #endBefore can only be used in a query that matches the constraint of query
that produced this partition.
Members
endBefore
The cursor that defines the first result after this partition or
undefined
if this is the last partition. The cursor value must be
destructured when passed to
endBefore()
(for example with
query.endBefore(...queryPartition.endBefore)
).
Example
```
const query = firestore.collectionGroup('collectionId');
for await (const partition of query.getPartitions(42)) {
let partitionedQuery = query.orderBy(FieldPath.documentId());
if (partition.startAt) {
partitionedQuery = partitionedQuery.startAt(...partition.startAt);
}
if (partition.endBefore) {
partitionedQuery = partitionedQuery.endBefore(...partition.endBefore);
}
const querySnapshot = await partitionedQuery.get();
console.log(`Partition contained ${querySnapshot.length} documents`);
}
```
startAt
The cursor that defines the first result for this partition or
undefined
if this is the first partition. The cursor value must be
destructured when passed to
startAt()
(for example with
query.startAt(...queryPartition.startAt)
).
Example
```
const query = firestore.collectionGroup('collectionId');
for await (const partition of query.getPartitions(42)) {
let partitionedQuery = query.orderBy(FieldPath.documentId());
if (partition.startAt) {
partitionedQuery = partitionedQuery.startAt(...partition.startAt);
}
if (partition.endBefore) {
partitionedQuery = partitionedQuery.endBefore(...partition.endBefore);
}
const querySnapshot = await partitionedQuery.get();
console.log(`Partition contained ${querySnapshot.length} documents`);
}
```
Methods
toQuery
()
→ {
Query
.<T>}
Returns a query that only encapsulates the documents for this partition.
Returns:
Example
```
const query = firestore.collectionGroup('collectionId');
for await (const partition of query.getPartitions(42)) {
const partitionedQuery = partition.toQuery();
const querySnapshot = await partitionedQuery.get();
console.log(`Partition contained ${querySnapshot.length} documents`);
}
```