-3

In my firebase's database I have Users and every user has multiple stores that he ordered from and every store has multiple orders. To fetch all the orders for specific store I write the following query and it works fine.

 QuerySnapshot result = await Firestore.instance
    .collection('users')
    .document(userID)
    .collection('Stores').
    document(storeID).getDocuments();

However, I do not need that. I just need the stores that the user ordered from. In other words, I need list of storeIDs for specific user.

Here is my code but it doesn't work.

QuerySnapshot result = await Firestore.instance
    .collection('users')
    .document(userID)
    .collection('Stores').getDocuments();

I just want the IDs

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441

1 Answers1

0

It's not possible with web and mobile clients to get only the IDs without the entire set of documents and their data. If you want a list of all IDs for all documents in a collection or subcolleciton, you're going to have to query that collection as you currently show in the second example. You can easily extract the IDs from the returned documents in the QuerySnapshot. But you are still paying the cost of a document read for each document in the collection, and waiting for all of their contents to transfer.

If you want, you can create your own backend endpoint API to use a server SDK to query for only the IDs, and return only the IDs, but you are still paying a document read for document.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441