Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit da4f8f8

Browse files
fix: Remove DocumentReference from cursor (#1882)
* remove DocumentReference from cursor * remove the warning --------- Co-authored-by: Mark Duckworth <[email protected]>
1 parent 1f5abb8 commit da4f8f8

3 files changed

Lines changed: 15 additions & 23 deletions

File tree

dev/src/reference.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,27 +1900,14 @@ export class Query<
19001900
DocumentSnapshot<AppModelType, DbModelType> | unknown
19011901
>
19021902
): FieldOrder[] {
1903-
// Add an implicit orderBy if the only cursor value is a DocumentSnapshot
1904-
// or a DocumentReference.
1903+
// Add an implicit orderBy if the only cursor value is a DocumentSnapshot.
19051904
if (
19061905
cursorValuesOrDocumentSnapshot.length !== 1 ||
1907-
!(
1908-
cursorValuesOrDocumentSnapshot[0] instanceof DocumentSnapshot ||
1909-
cursorValuesOrDocumentSnapshot[0] instanceof DocumentReference
1910-
)
1906+
!(cursorValuesOrDocumentSnapshot[0] instanceof DocumentSnapshot)
19111907
) {
19121908
return this._queryOptions.fieldOrders;
19131909
}
19141910

1915-
// TODO(b/296435819): Remove this warning message.
1916-
if (cursorValuesOrDocumentSnapshot[0] instanceof DocumentReference) {
1917-
// eslint-disable-next-line no-console
1918-
console.warn(
1919-
`Warning: Passing DocumentReference into a cursor without orderBy clause is not an intended
1920-
behavior. Please use DocumentSnapshot or add an explicit orderBy on document key field.`
1921-
);
1922-
}
1923-
19241911
const fieldOrders = this._queryOptions.fieldOrders.slice();
19251912
const fieldsNormalized = new Set([
19261913
...fieldOrders.map(item => item.field.toString()),

dev/system-test/firestore.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ describe('Firestore class', () => {
309309

310310
const documents: QueryDocumentSnapshot<DocumentData>[] = [];
311311
for (const partition of partitions) {
312-
let partitionedQuery: Query = collectionGroup;
312+
let partitionedQuery: Query = collectionGroup.orderBy(
313+
FieldPath.documentId()
314+
);
313315
if (partition.startAt) {
314316
partitionedQuery = partitionedQuery.startAt(...partition.startAt);
315317
}
@@ -1740,9 +1742,10 @@ describe('Query class', () => {
17401742
expectDocs(res, {foo: 'b'});
17411743
});
17421744

1743-
it('startAt() adds implicit order by for DocumentReference', async () => {
1745+
it('startAt() adds implicit order by for DocumentSnapshot', async () => {
17441746
const references = await addDocs({foo: 'a'}, {foo: 'b'});
1745-
const res = await randomCol.startAt(references[1]).get();
1747+
const docSnap = await references[1].get();
1748+
const res = await randomCol.startAt(docSnap).get();
17461749
expectDocs(res, {foo: 'b'});
17471750
});
17481751

@@ -3046,16 +3049,18 @@ describe('Aggregates', () => {
30463049
await randomCol.doc('doc6').set({foo: 'bar'});
30473050
await randomCol.doc('doc7').set({foo: 'bar'});
30483051

3049-
const count1 = randomCol.startAfter(randomCol.doc('doc3')).count();
3052+
const docSnap = await randomCol.doc('doc3').get();
3053+
3054+
const count1 = randomCol.startAfter(docSnap).count();
30503055
await runQueryAndExpectCount(count1, 4);
30513056

3052-
const count2 = randomCol.startAt(randomCol.doc('doc3')).count();
3057+
const count2 = randomCol.startAt(docSnap).count();
30533058
await runQueryAndExpectCount(count2, 5);
30543059

3055-
const count3 = randomCol.endAt(randomCol.doc('doc3')).count();
3060+
const count3 = randomCol.endAt(docSnap).count();
30563061
await runQueryAndExpectCount(count3, 3);
30573062

3058-
const count4 = randomCol.endBefore(randomCol.doc('doc3')).count();
3063+
const count4 = randomCol.endBefore(docSnap).count();
30593064
await runQueryAndExpectCount(count4, 2);
30603065

30613066
const count5 = randomCol.offset(6).count();

dev/test/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,7 @@ describe('startAt() interface', () => {
23022302
firestore = firestoreInstance;
23032303
return snapshot('collectionId/doc', {foo: 'bar'}).then(doc => {
23042304
let query: Query = firestore.collection('collectionId');
2305-
query = query.startAt(doc.ref);
2305+
query = query.startAt(doc);
23062306
return query.get();
23072307
});
23082308
});

0 commit comments

Comments
 (0)