Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#2,350 コメント 4 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
firebase, node.js, typescript
領域
databases

調査の方向性

issue に示されている admin.database.Database.ref のクエリチェーンから始め、特に orderByKey()、limitToFirst()、startAfter() を確認します。提供されているページネーションループを使って、SDK 11.11.0 と 11.4.1 の違いを再現します。十分な数のキーが残っている場合に、lastDocument.key の後の 100 件を要求するクエリが 100 件を返し、リグレッションに対するカバレッジがあることを完了条件とします。

索引モデルが issue の本文から書いたものです。

説明

api: database
[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;
  }
主要言語
TypeScript
スター
1.7k
フォーク
419
平均マージ
4日 20時間
マージ済み PR(30日)
16

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firebase/firebase-admin-node のほかの issue

firebase/firebase-admin-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。