Enric Ribas
Enric Ribas

Reputation: 629

Firestore returning no records yet, I see them in console

from my app and javascript console

firestore.collection('organizations/f1f4002a-1fb2-4805-baf1-a1a709f228e9/emailsSent').get().then(console.log)

returns QuerySnapshot with empty: true

yet there IS clearly one record. Every other query I write seems to work. ie assignmentLogs, emails, etc.

```

firebase console

I feel like I'm going crazy and it's probably something really stupid so I apologize in advance.

Upvotes: 3

Views: 1645

Answers (2)

Doug Stevenson
Doug Stevenson

Reputation: 317828

Notice that the document name 455...2c2 is shown in italics in the console, which definitely not the normal case for documents displayed in the console. That italics actually means that the document was deleted, however, it probably contains other subcollections that were not deleted (try clicking into it).

Since Firestore queries are shallow, the get() you're trying to perform is not going to yield any documents, because there are not actually any documents in that collection.

Something in your system may have deleted that document and not deleted its subcollections, so it's probably worthwhile to figure out what's responsible for that delete, and modify it so that it deletes its subcollections as well (otherwise they will remain "orphaned" in your database like this indefinitely).

Meanwhere, there's nothing much you can do about your query as shown - it's returning the correct results.

Upvotes: 6

Jason Berryman
Jason Berryman

Reputation: 4908

Try this...

const db = admin.firestore();

return db.collection('organizations/f1f4002a-1fb2-4805-baf1-a1a709f228e9/emailsSent').get().then(snapshot => {
  snapshot.forEach (doc => {
    console.log(`ID: ${doc.id}`);
    console.log(doc.data());
  });
});

Upvotes: 0

Related Questions