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

207
Views
¿Cómo usar la consulta aleatoria en firestore v9?

Digamos que tengo 9 documentos en una colección, 3 de ellos contienen la sección: 1, 3 de ellos contienen la sección: 2, 3 de ellos contienen la sección: 3.

Quiero obtener dos documentos aleatorios que contengan la sección: 2.

algo como:

 const colRef = collection(db, "readingfiles"); const q = query(colRef, where("section", "==", 2), orderBy("random"), limit(2)); getDocs(q).then((snapshot) => { snapshot.docs.forEach((doc) => { console.log(doc.data()); }) }).catch((err) => { console.log(err.message); });

Una forma que encontré es dar una identificación a cada documento y luego usar where() con números aleatorios para obtener datos.

Me pregunto si hay alguna manera fácil y efectiva.
algo como:

 const q = query(colRef, where("section", "==", 2), getRandom(2));

o

 const q = query(colRef, where("section", "==", 2), orderBy("__random__"), limit(2));
about 4 years ago · Juan Pablo Isaza
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!