Skip to content

Commit 9f73729

Browse files
committed
fix(firestore, count): add countFromServer API, delegates to count
keeps us closer to JS API, Fixes #6654
1 parent 3857439 commit 9f73729

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

packages/firestore/e2e/Aggregate/count.e2e.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ describe('firestore().collection().count()', function () {
4848
const qs = await colRef.count().get();
4949
qs.data().count.should.eql(3);
5050
});
51+
it('gets countFromServer of collection reference - unfiltered', async function () {
52+
const colRef = firebase.firestore().collection(`${COLLECTION}/count/collection`);
53+
54+
const doc1 = colRef.doc('doc1');
55+
const doc2 = colRef.doc('doc2');
56+
const doc3 = colRef.doc('doc3');
57+
await Promise.all([
58+
doc1.set({ foo: 1, bar: { value: 1 } }),
59+
doc2.set({ foo: 2, bar: { value: 2 } }),
60+
doc3.set({ foo: 3, bar: { value: 3 } }),
61+
]);
62+
63+
const qs = await colRef.countFromServer().get();
64+
qs.data().count.should.eql(3);
65+
});
5166
it('gets correct count of collection reference - where equal', async function () {
5267
const colRef = firebase.firestore().collection(`${COLLECTION}/count/collection`);
5368

packages/firestore/lib/FirestoreQuery.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ export default class FirestoreQuery {
140140
);
141141
}
142142

143+
countFromServer() {
144+
return this.count();
145+
}
146+
143147
endAt(docOrField, ...fields) {
144148
return new FirestoreQuery(
145149
this._firestore,

packages/firestore/lib/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,11 @@ export namespace FirebaseFirestoreTypes {
941941
*/
942942
count(): AggregateQuery<{ count: AggregateField<number> }>;
943943

944+
/**
945+
* Same as count()
946+
*/
947+
countFromServer(): AggregateQuery<{ count: AggregateField<number> }>;
948+
944949
/**
945950
* Creates and returns a new Query that ends at the provided document (inclusive). The end
946951
* position is relative to the order of the query. The document must contain all of the

0 commit comments

Comments
 (0)