mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-01-12 22:50:20 +08:00
bug(firestore): fix multiple cursor query
* fixed, fieldPath:'__name__' should be added once for queries with multiple cursors * fixed es-lint errors * test(firestore): test for multiple query Co-authored-by: Mohammed Maaz <maazproductions25@gmail.com> Co-authored-by: Mike Diarmid <mike.diarmid@gmail.com>
This commit is contained in:
@@ -162,4 +162,25 @@ describe('firestore().collection().startAfter()', () => {
|
||||
qs.docs.length.should.eql(1);
|
||||
qs.docs[0].id.should.eql('doc3');
|
||||
});
|
||||
|
||||
it('runs startAfter & endBefore in the same query', async () => {
|
||||
const colRef = firebase.firestore().collection('v6/startAfter/snapshot');
|
||||
const doc1 = colRef.doc('doc1');
|
||||
const doc2 = colRef.doc('doc2');
|
||||
const doc3 = colRef.doc('doc3');
|
||||
|
||||
await Promise.all([doc1.set({ age: 1 }), doc2.set({ age: 2 }), doc3.set({ age: 3 })]);
|
||||
|
||||
const first = await doc1.get();
|
||||
const last = await doc3.get();
|
||||
|
||||
const inBetween = await colRef
|
||||
.orderBy('age', 'asc')
|
||||
.startAfter(first)
|
||||
.endBefore(last)
|
||||
.get();
|
||||
|
||||
inBetween.docs.length.should.eql(1);
|
||||
inBetween.docs[0].id.should.eql('doc2');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,6 +72,11 @@ export default class FirestoreQuery {
|
||||
|
||||
for (let i = 0; i < currentOrders.length; i++) {
|
||||
const order = currentOrders[i];
|
||||
//skip if fieldPath is '__name__'
|
||||
if (order.fieldPath === '__name__') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const value = documentSnapshot.get(order.fieldPath);
|
||||
|
||||
if (value === undefined) {
|
||||
@@ -87,10 +92,14 @@ export default class FirestoreQuery {
|
||||
|
||||
// Based on https://github.com/invertase/react-native-firebase/issues/2854#issuecomment-552986650
|
||||
if (modifiers._orders.length) {
|
||||
modifiers._orders.push({
|
||||
fieldPath: '__name__',
|
||||
direction: modifiers._orders[modifiers._orders.length - 1].direction,
|
||||
});
|
||||
const lastOrder = modifiers._orders[modifiers._orders.length - 1];
|
||||
//push '__name__' field only if not present already
|
||||
if (lastOrder.fieldPath !== '__name__') {
|
||||
modifiers._orders.push({
|
||||
fieldPath: '__name__',
|
||||
direction: lastOrder.direction,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
modifiers._orders.push({
|
||||
fieldPath: '__name__',
|
||||
|
||||
Reference in New Issue
Block a user