1
QuerySnapshot profilesSnap = await _firestore
          .collection('users')
          .doc(userId)
          .collection('profiles').doc("default").collection("incomeRecords")
          .get()

above code returns result but below code returns empty list

final QuerySnapshot profilesSnap = await _firestore
          .collection('users')
          .doc(userId)
          .collection('profiles')

enter image description here

1
  • 4
    We can't see the data in your database, so we don't know what any of these queries are going to do. Please edit the question to show us exactly what you have (maybe a screenshot) and describe what you expect the query to return. Commented Dec 11, 2025 at 14:10

2 Answers 2

3

Most likely your database doesn't have any documents in the profiles collection. That is a totally valid state for the system to be in, and in fact there needs to be no document in the default collection for the first snippet to be able to read incomeRecords from under it.

You can recognize this situation, because the Firestore console will show placeholder document IDs in the profiles collection which are shown in italics, like the common document here:

enter image description here

Such placeholders are just shown in the console so that you can get to the documents under them, but there actually is no document for the placeholder - so they won't be returned in API calls.

When you select an italic placeholder document ID, there should be a message to that effect in the bottom right of the console explaining that too, like in the screenshot below where I selected the [email protected] document:

enter image description here


If you want to be able to read the user profiles, you'll need to make sure that actual documents exist in that collection. It's OK for the document to have no data, but you must create it with a call to add on the profiles collection reference or set on the DocumentReference in there.

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


This is a very common source of confusion for developers, so I recommend also checking out:

Sign up to request clarification or add additional context in comments.

Comments

0

Please set at least one property field for profiles/default, otherwise Firestore won't list any of its sub-collections.

Firestore will only list documents in a collection if those documents actually exist with at least one field set.

If there's no fields set to the documents, Firestore treats that document as basically non-existent, hence this is an expected result.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.