0

If have a collection like this

Shop(Collection):
     -shopId(Document)
         -name
         -adresse
         -itemSold (Nested Collection)
             -itemId
                 -....
                 -....

how can i write a query in flutter that will return me only the shop that have a specific itemId in itemSold collection.

Its this gonna cost many read?

How are you handling that kind of tree on your side i am pretty new in noSQL database. Im use to traditionnal database.

Jason Simard
  • 103
  • 5
  • 18
  • 1
    Hi, If you feel an answer solved the problem, please mark it as 'accepted' by clicking the green check mark. This helps keep the focus on older SO which still don't have answers. – Itiel Maimon Aug 28 '20 at 08:16
  • 1
    Does this answer your question? [Firestore query subcollections](https://stackoverflow.com/questions/46573014/firestore-query-subcollections) – Emil Gi Aug 28 '20 at 08:17

1 Answers1

2

You can use the .where method.

In your case something like this:

DocumentReference shopInstance = Firestore.instance
        .collection('shops')
        .document('shopsID'):
await shopInstance
      .collection('itemSold')
      .where('itemID', isEqualTo: 'someId')
      .getDocuments()
      .then()...
Itiel Maimon
  • 834
  • 2
  • 9
  • 26
  • Hello Itiel , thanks for the answer! It give me a better idea. Do you know if that kind of setup is good or bad? I think the document will be smaller but it will make more reads count. – Jason Simard Aug 28 '20 at 15:48
  • Take a look here: https://stackoverflow.com/questions/47146115/firestore-pricing-does-the-amount-of-documents-in-a-collection-matters – Itiel Maimon Aug 28 '20 at 18:12