Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(firestore, iOS): account for filters in getAggregateFromServer with collection groups #8259

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/firestore/e2e/Aggregate/AggregateQuery.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,5 +563,49 @@ describe('getAggregateFromServer()', function () {
data.averageBaz.should.eql(-0.19999999999999998);
});
});

describe('collectionGroup()', function () {
it('test count, sum, average with collectionGroup', async function () {
const {
getAggregateFromServer,
doc,
setDoc,
collection,
getFirestore,
count,
average,
collectionGroup,
sum,
FieldPath,
} = firestoreModular;
const firestore = getFirestore();

const colRef = collection(firestore, 'collectionGroup');

await Promise.all([
setDoc(doc(colRef, 'one'), { docId: '123', status: 'paid', amount: 100 }),
setDoc(doc(colRef, 'two'), { docId: '123', status: 'paid', amount: 200 }),
setDoc(doc(colRef, 'three'), { docId: '123', status: 'unpaid', amount: 400 }),
]);

const query = collectionGroup(firestore, 'collectionGroup')
.where('docId', '==', '123')
.where('status', '==', 'paid');

const aggregateSpec = {
countCollection: count(),
averageAmount: average(new FieldPath('amount')),
sumAmount: sum(new FieldPath('amount')),
};

const result = await getAggregateFromServer(query, aggregateSpec);

const data = result.data();

data.countCollection.should.eql(2);
data.averageAmount.should.eql(150);
data.sumAmount.should.eql(300);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,18 @@ - (void)invalidate {
: (RCTPromiseRejectBlock)reject) {
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
databaseId:databaseId];
FIRQuery *query = [RNFBFirestoreCommon getQueryForFirestore:firestore path:path type:type];

FIRQuery *firestoreBaseQuery = [RNFBFirestoreCommon getQueryForFirestore:firestore
path:path
type:type];
RNFBFirestoreQuery *firestoreQuery =
[[RNFBFirestoreQuery alloc] initWithModifiers:firestore
query:firestoreBaseQuery
filters:filters
orders:orders
options:options];

FIRQuery *query = [firestoreQuery instance];

NSMutableArray<FIRAggregateField *> *aggregateFields =
[[NSMutableArray<FIRAggregateField *> alloc] init];
Expand Down
Loading
Loading