I am attempting to built a chat app with Vue, Firebase Firestore and Firebase authentication. After registering a user, logging in, and submitting a message, I am using the getMessage function below to retrieve the messages from a collection assigned to a doc for the currently logged-in user.
const messages = ref([])
const getMessages = () => {
firebase.firestore().collection("users").doc(firebase.auth().currentUser.uid).collection('messages').orderBy('timestamp')
.onSnapshot(snap => {
messages.value = []
snap.forEach(doc => {
var msg = doc.data();
msg.id = doc.id;
messages.value.push(msg)
})
})
},
However, I have multiple registered users and am wanting to retrieve messages for all the users, not just the currentUser. How can I set up the above firestore collection method chain to retrieve messages for all of the registered users, not just currentUser?