score:3

Accepted answer

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.

score: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.


Related Query

More Query from same tag