firebase / firebase/firebase-admin-node

Firebase query orderByKey().limitToFirst(n).startAfter() returns n-1 items iso n

Aperta
#2,350 4 commenti 1 reazione 0 assegnatari Vedi su GitHub
api: database
Lingua principale
TypeScript
Stelle
1.7k
Fork
419
Merge medio
3g 10h
PR unite (30g)
16

Descrizione

### [READ] Step 1: Are you in the right place?
yes

### [REQUIRED] Step 2: Describe your environment

* Operating System version: Ubuntu 22.04 lts
* Firebase SDK version: 11.11.0
* Firebase Product: realtime database (auth, database, storage, etc)
* Node.js version: 16.20.2
* NPM version: 8.19.4

### [REQUIRED] Step 3: Describe the problem

Firebase query of type:
`admin.database.Database.ref('collection').orderByKey().limitToFirst(100).startAfter(lastKey)` only returns 99 items iso 100 even if more keys are in the firebase realtime database.

On version 11.4.1 of firebase-admin this query behaves as expected and 100 items are returned.

#### Steps to reproduce:

What happened? How can we make the problem occur?
This could be a description, log/console output, etc.

#### Relevant Code:

```typescript
let query;
let lastDocument = null;
let lastBatchSize: number = 100;

while (lastBatchSize === 100) {
query = database.ref('collection').orderByKey()
.limitToFirst(100);

if (lastDocument !== null) {
query = query.startAfter(lastDocument.key);
}

const snapshot = await query.get();
const keys = Object.keys(snapshot.val() || {});
const docs = keys.map((key) => snapshot.child(key));

if (docs.length === 0) break;
console.log("docs length " + docs.length); //prints 99 on 11.11.0, prints 100 on 11.4.1

if (docs.length) {
lastDocument = docs[docs.length - 1];
}
lastBatchSize = docs.length;
}
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con la catena di query admin.database.Database.ref mostrata nell’issue, in particolare orderByKey(), limitToFirst() e startAfter(). Riproduci la differenza tra SDK 11.11.0 e 11.4.1 usando il ciclo di paginazione fornito. Il lavoro è completo quando una query che richiede 100 elementi dopo lastDocument.key restituisce 100 finché rimangono chiavi sufficienti, con una copertura per la regressione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
firebase, node.js, typescript
Ambito
databases
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.