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

266
Views
Converting firebase 8 code to firebase 9 code (web, javascript) to fetch collection within collection

Hello I would like to convert the following firebase 8 code to firebase 9 and have no clue how to do it - any help would be welcome!

This piece of code should go inside the userDoc and then fetch the collection that is insdie that document and return all of the posts that belong to that user

if (userDoc) {
    user = userDoc.data()
    const postsQuery = userDoc.ref
        .collection('posts')
        .where('published', '==', true)
        .orderBy('createdAt', 'desc')
        .limit(5)
    posts = (await postsQuery.get()).docs.map(postToJSON)
}

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Firestore's documentation has examples for both V8 and V9 so you can easily compare them and modify your code. Just switch to modular tab for the new syntax. The code in question would be like:

import { collection, query, where, getDocs, orderBy, limit } from "firebase/firestore";

const q = query(collection(db, "posts"), where("published", "==", true), orderBy("createdAt", "desc"), limit(5));

const querySnapshot = await getDocs(q);

posts = querySnapshot.docs.map(postToJSON)
about 4 years ago · Juan Pablo Isaza 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!