Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

356
Views
¿Hay alguna manera de seleccionar solo ciertos campos de Firestore?

Estoy trabajando en un problema de rendimiento de una función, que tarda 15 segundos en responder, lo que hace una solicitud a Firebase para todos los documentos que son "ErrorID" "==" "0" El problema es que hay muchos documentos y son amables de objetos muy grandes, y solo necesito DOS CAMPOS (Order and Amount) de cada documento, hay alguna forma de solicitar solo esos dos campos que cumplen la condición?

Algo como :

 firestore.collection("purchases").where("ErrorID", "==", "0").get(Order, Amount);

La función de la que estoy hablando:

 const totalEarn = async (req, res, next) => { const DAY = 86400000; const WEEK = 604800016; const MONTH = 2629800000; try { let snap = await firestore.collection("purchases").where("ErrorID", "==", "0").get(); // CONDITION let totalToday = 0; let totalYesterday = 0; let totalLastWeek = 0; let totalLastMonth = 0; let now = Date.now(); let Yesterday = now - 86400000; await snap.forEach((doc) => { // THIS FOR EACH TAKES TOO MUCH TIME let info = doc.data(); let time = info.Order.split("-")[2]; // FIRESTORE FIELD -> ORDER let amount = info.AmountEur * 1; // FIRESTORE FIELD -> AMOUNT if (time > now - DAY) { totalToday = totalToday + amount; } if (time < now - DAY && time > Yesterday - DAY) { totalYesterday = totalYesterday + amount; } if (time > now - WEEK) { totalLastWeek = totalLastWeek + amount; } if (time > now - MONTH) { totalLastMonth = totalLastMonth + amount; } }); res.send({ status: true, data: { totalToday: totalToday.toFixed(2), totalYesterday: totalYesterday.toFixed(2), totalLastWeek: totalLastWeek.toFixed(2), totalLastMonth: totalLastMonth.toFixed(2), }, }); } catch (error) { res.status(410).send({ status: false, error: "some error occured counting the numbers", e: error.message, }); } };

El documento del que estoy hablando

El documento del que estoy hablando

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si usa el cliente Firestore Node.JS o Firebase Admin SDK, puede usar select() para seleccionar campos:

 import { Firestore } from "@google-cloud/firestore"; const firestore = new Firestore(); const snap = firestore .collection("purchases") .where("ErrorID", "==", "0") .select("Order", "Amount") .get();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!