Is it possible to retrieve all elements from a collection in real-time?
I have been searching for documentation on this topic, but haven't found anything. While I know it's feasible to fetch all data from a collection, I am unsure if it can be done in real-time.
The code snippet below currently only works once when the page is loaded:
const querySnapshot = await getDocs(collection(db, "users"));
querySnapshot.forEach((doc) => {
console.log(`${doc.id} => ${doc.data()}`);
});
Are you aware of any method to achieve similar results in real-time using "onSnapshot
"? Additionally, I am utilizing Next 13 if that provides any additional context or assistance.