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

153
Views
How can i change this Firebase version 8 code to version 9

How to do this with Firebase version 9 Web SDK

db.collection('rooms')
 .doc(id)
 .collection('messages')
 .orderBy('timestamp', 'asc')
 .onSnapshot((snapshot) => 
   setState(snapshot.docs.map(doc => 
   doc.data()))
 )
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The following should do the trick:

import { collection, query, orderBy, onSnapshot } from "firebase/firestore"; 

const id = ...;

const messagesColRef = collection(db, "rooms", id, "comments");
const messagesQuery = query(messagesColRef, orderBy("timestamp"));
onSnapshot(messagesQuery, (snapshot) => {
   setState(snapshot.docs.map(doc => 
   doc.data()))
});

Have a look at the Firestore reference.

about 4 years ago · Juan Pablo Isaza Report

0

related to your question indirectly, if you want to procrastinate and upgrade to 9 but leave your code as is, you can use the version 9 compat (Compatibility) link. Just replace your version 8 with version 9 and add "-compat" before ending '.js' .e.g.

<script src="https://www.gstatic.com/firebasejs/9.3.0/firebase-app-compat.js"></script>

this way don't change your code while using latest version of firebase. The disadvantage is that you won't benefit from module nature firebase 9.

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!