0

I am configuring my Vue/Firebase chat app to save the email address of a registered user in a Firestore collection when the registered user is logged in and submits a message. The Firestore Database looks like the following, with the users added to the "user" collection, and with each user containing a "message" collection:

enter image description here

In my code, I am attempting to add a function that returns the email addresses listed in the "users" collection, as seen in the screenshot:

const contactList = ref([])

    const getContacts = () => {
      firebase.firestore().collection("users").onSnapshot(snap => {
        contactList.value = []
        snap.forEach(doc => {
          const users = doc.data();
          users.id = doc.id;
          contactList.value.push(users)
          console.log(users)
        })
      })
    },

However, this function does not simply return those email addresses in the user collection, since .collection('users') is the first collection in a chain of docs and collections as indicated in the screenshot. How can I go about returning the list of users in the "users" collection when .collection('users') is the first in a chain of docs and collections?

JS_is_awesome18
  • 1,587
  • 7
  • 23
  • 67

1 Answers1

0

The document titles are shown in italic, meaning that there are actually no documents with that ID (also shown in the bottom) right and the console merely shows them in order to be able to show the subcollections.

The API won't return such non-existing documents. You'll have to create the document to be able to then read them, for example by running a collection group query over all messages collections and checking if their parent document exists already.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807