Skip to content

Commit

Permalink
fix(firestore, count): add countFromServer API, delegates to count
Browse files Browse the repository at this point in the history
keeps us closer to JS API, Fixes #6654
  • Loading branch information
mikehardy committed Nov 6, 2022
1 parent 3857439 commit 9f73729
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/firestore/e2e/Aggregate/count.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ describe('firestore().collection().count()', function () {
const qs = await colRef.count().get();
qs.data().count.should.eql(3);
});
it('gets countFromServer of collection reference - unfiltered', async function () {
const colRef = firebase.firestore().collection(`${COLLECTION}/count/collection`);

const doc1 = colRef.doc('doc1');
const doc2 = colRef.doc('doc2');
const doc3 = colRef.doc('doc3');
await Promise.all([
doc1.set({ foo: 1, bar: { value: 1 } }),
doc2.set({ foo: 2, bar: { value: 2 } }),
doc3.set({ foo: 3, bar: { value: 3 } }),
]);

const qs = await colRef.countFromServer().get();
qs.data().count.should.eql(3);
});
it('gets correct count of collection reference - where equal', async function () {
const colRef = firebase.firestore().collection(`${COLLECTION}/count/collection`);

Expand Down
4 changes: 4 additions & 0 deletions packages/firestore/lib/FirestoreQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export default class FirestoreQuery {
);
}

countFromServer() {
return this.count();
}

endAt(docOrField, ...fields) {
return new FirestoreQuery(
this._firestore,
Expand Down
5 changes: 5 additions & 0 deletions packages/firestore/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,11 @@ export namespace FirebaseFirestoreTypes {
*/
count(): AggregateQuery<{ count: AggregateField<number> }>;

/**
* Same as count()
*/
countFromServer(): AggregateQuery<{ count: AggregateField<number> }>;

/**
* Creates and returns a new Query that ends at the provided document (inclusive). The end
* position is relative to the order of the query. The document must contain all of the
Expand Down

1 comment on commit 9f73729

@vercel
Copy link

@vercel vercel bot commented on 9f73729 Nov 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.