Skip to content

Commit 9ac0394

Browse files
authored
fix: Aggregate query readtime bug (#2331)
* fix: Aggregate query readtime bug * improve test
1 parent 5937b93 commit 9ac0394

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

dev/src/reference/aggregate-query.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ export class AggregateQuery<
335335
if (transactionOrReadTime instanceof Uint8Array) {
336336
runQueryRequest.transaction = transactionOrReadTime;
337337
} else if (transactionOrReadTime instanceof Timestamp) {
338-
runQueryRequest.readTime = transactionOrReadTime;
338+
runQueryRequest.readTime = transactionOrReadTime.toProto().timestampValue;
339339
} else if (transactionOrReadTime) {
340340
runQueryRequest.newTransaction = transactionOrReadTime;
341341
}

dev/system-test/firestore.ts

+20
Original file line numberDiff line numberDiff line change
@@ -5010,6 +5010,26 @@ describe('Aggregation queries', () => {
50105010
return Promise.all(sets);
50115011
}
50125012

5013+
it('can run count within a transaction with readtime', async () => {
5014+
const doc = col.doc();
5015+
const writeResult: WriteResult = await doc.create({some: 'data'});
5016+
5017+
const count = await firestore.runTransaction(t => t.get(col.count()), {
5018+
readOnly: true,
5019+
readTime: writeResult.writeTime,
5020+
});
5021+
expect(count.data().count).to.equal(1);
5022+
5023+
const countBefore = await firestore.runTransaction(
5024+
t => t.get(col.count()),
5025+
{
5026+
readOnly: true,
5027+
readTime: Timestamp.fromMillis(writeResult.writeTime.toMillis() - 1),
5028+
}
5029+
);
5030+
expect(countBefore.data().count).to.equal(0);
5031+
});
5032+
50135033
it('can run count query using aggregate api', async () => {
50145034
const testDocs = {
50155035
a: {author: 'authorA', title: 'titleA'},

0 commit comments

Comments
 (0)