I'm trying to access the firebase firestore documents inside subcollection (messages):
user > user.uid > messages > docRef.id > date: Date.now()
text: userText
userEmail: user.email
userName: display.name
I used the following:
const snapRef2 = collection(db, "users/" + user.uid + "/messages")
onSnapshot(snapRef2, (snapshot) => {
snapshot.forEach((doc) => {
console.log(doc.data());
})
})
But this method works only when user.uid is a string like: const snapRef2 = collection(db, "users/randomstring/messages")
How do I access the documents inside messages?
const snapRef2 = collection(db, `users/${user.uid}/messages`)
Make sure to use back ticks instead of quotation marks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With