Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Firestore]

Aperta
#3,036 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 7 giorni

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Riproduci il report con la query TypeScript Firestore usando Filter.or(), query.aggregate() e AggregateField.average(), confrontandola con query.get(). Inizia tracciando il percorso di aggregazione per i filtri disgiuntivi nell’SDK e aggiungi un test di regressione che copra documenti con valutazioni 1 e 3. Il lavoro è completato quando l’aggregato restituisce 2 mentre la query esistente continua a restituire entrambi i documenti.

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

Descrizione

api: firestore needs-triage

Step 2: Describe your environment
Operating System version: Ubuntu 24.04
Firebase SDK version: [email protected]
@google-cloud/firestore version: 7.11.0
Firebase Product: Firestore
Node.js version: v20.19.0
NPM version: 11.3.0

Step 3: Describe the problem
When using AggregateField.average() on a query that includes Filter.or(), the aggregate returns an incorrect value. It seems to only consider one of the matching documents instead of computing the average across all matched documents.

Steps to reproduce:
Create a collection with documents containing a numeric field participantsRatingAvg
Query using Filter.or() combined with other where clauses
Use AggregateField.average("participantsRatingAvg") on that query
The result is incorrect
Sample code:

import { Filter, AggregateField } from "firebase-admin/firestore";

// Query with Filter.or()
const query = db.collectionGroup("events")
  .where("participantsCount", ">", 0)
  .where("activityId", "==", "some-activity-id")
  .where("dateTime", ">=", startDate)
  .where("dateTime", "<=", endDate)
  .where(
    Filter.or(
      Filter.where("residenceId", "==", residenceId),
      Filter.where("executionResidenceId", "==", residenceId)
    )
  )
  .where("status", "in", ["accepted", "invoiced", "signed", "custom"]);

// First, verify the documents exist and their field values
const snapshot = await query.get();
console.log("Documents found:", snapshot.docs.map(d => ({
  rating: d.data().participantsRatingAvg,
  ratingType: typeof d.data().participantsRatingAvg,
  hasField: "participantsRatingAvg" in d.data(),
})));
// Output:
// [
//   { rating: 1, ratingType: 'number', hasField: true },
//   { rating: 3, ratingType: 'number', hasField: true }
// ]

// Now run the aggregate
const aggregateSnapshot = await query.aggregate({
  avgRating: AggregateField.average("participantsRatingAvg"),
}).get();

console.log("Average:", aggregateSnapshot.data().avgRating);
// Expected: 2 (average of 1 and 3)
// Actual: 3 (only considers one document)

Expected behavior:
AggregateField.average("participantsRatingAvg") should return 2 (the average of 1 and 3).

Actual behavior:
AggregateField.average("participantsRatingAvg") returns 3, ignoring one of the documents that matches the query.

Additional context:
The same query with .get() correctly returns both documents
Both documents have participantsRatingAvg as a number type (verified with typeof)
Both documents have the field present (verified with "field" in doc.data())
AggregateField.sum() and AggregateField.count() on the same query were not verified
The issue seems specific to queries using Filter.or() combined with aggregations

Workaround:
Fetch documents with .get() and compute the average manually:

const snapshot = await query.get();
const docs = snapshot.docs.map(d => d.data());
const validRatings = docs.filter(d => typeof d.participantsRatingAvg === "number" && d.participantsRatingAvg > 0);
const avgRating = validRatings.length > 0
  ? validRatings.reduce((sum, d) => sum + d.participantsRatingAvg, 0) / validRatings.length
  : 0;

Best regards

Lingua principale
TypeScript
Stelle
1.8k
Fork
420
Merge medio
5g 6h
PR unite (30g)
11

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di firebase/firebase-admin-node

Tutte le issue di firebase/firebase-admin-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.