简体   繁体   中英

How to handle nested collection query in cloud flutter firestore?

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.

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()...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM