Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firestore query returns no documents even though they are shown in the console in italics

Firestore data structure:  messages

I am trying to get all the document id from the (message) table but it returns undefined. However, when i try it with my another table (donor), it is working.

I am wondering, in the message table, is it because the documents refers to a collection, instead of some fields, that’s why it becomes undefined?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Anyways, my question is, how to get all the document id from my message table? My approach for the message returns undefined.

db.collection('messages')
  .get()
  .then((querySnapshot) => {
    querySnapshot.forEach((doc) => console.log(doc.data()));
  });

db.collection('donor')
  .get()
  .then((querySnapshot) => {
    querySnapshot.forEach((doc) => console.log(doc.data()));
  });

>Solution :

There are no documents in your messages collection. You just have chats under document IDs, which causes the Firebase console to show the document IDs of the messages collection, so that you can select them. There is no way in the client-side SDKs to get those document IDs, so it’s best to create an empty document in messages before creating the subcollections.

To backfill the existing, missing messages documents, you can use a collection group query on chats, loop through those results, and write the parent document with something like document.ref.parent.parent.set({ dummy: true }).

Also see:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading