Firebase query orderByKey().limitToFirst(n).startAfter() returns n-1 items iso n
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- firebase, node.js, typescript
- Domain
- databases
Research direction
Start with the admin.database.Database.ref query chain shown in the issue, especially orderByKey(), limitToFirst(), and startAfter(). Reproduce the difference between SDK 11.11.0 and 11.4.1 using the provided pagination loop. Done means a query requesting 100 items after lastDocument.key returns 100 when enough keys remain, with coverage for the regression.
Written by the indexing model from the issue text.
Description
[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:
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;
}
- Dominant language
- TypeScript
- Stars
- 1.7k
- Forks
- 419
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 16
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from firebase/firebase-admin-node
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
firebase/firebase-admin-node#3234 ·
-
firebase/firebase-admin-node#3221 · 3 comments · 1 assignee ·
-
api: messaging
Difficulty 3/5 1-2 days Newbie friendliness 70/100
firebase/firebase-admin-node#3215 ·
-
api: messaging
Difficulty 5/5 Over a week Newbie friendliness 28/100
firebase/firebase-admin-node#3214 ·
-
api: firestore type: feature request
firebase/firebase-admin-node#3183 · 1 comment · 1 assignee ·
All issues in firebase/firebase-admin-node
Similar issues
-
bug(cli): hapi doctor inline-media prints a fabricated B:\ helper-script path in packaged installs Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Crush Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
catppuccin/catppuccin#3125 ·
-
Add a SECURITY.md Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
ElementsProject/cln-application#167 · 1 comment · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Quantco/pnpm-licenses#17 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100