title: flutter query multiple collections in firestore
body: <p>I am playing with flutter but I ran into an issue with firestore that I can't figure out.</p>
  
  <p>let's say I would like to retrieve the purchaser history of a customer and I have a firestore as described below so I have a collection of "user" within that contains a document of <code>user_id</code>'s and then within that, I have a "products" collection with a document that contains the <code>product_id</code>'s my aim is to gather the product id's for the selected user and then retrieve the products price from the products collection?</p>
  
  <ul>
  <li><p>users</p>
  
  <ul>
  <li>user_id_1
  
  <ul>
  <li>products
  
  <ul>
  <li>purchace_id
  
  <ul>
  <li>product_id</li>
  <li>quantity</li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul></li>
  <li><p>products</p>
  
  <ul>
  <li>product_id
  
  <ul>
  <li>product_desc</li>
  <li>price</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>the issue I am having is while I can get the id for the products from the user table but I can't then see a simple way of how I can use this data like with SQL where we would make a simple join on the product_id to get the price where the id's match?</p>
  
  <p>any help would be much appreciated.</p>
  
  <hr>
  
  <p>Thanks for replying Frank van Puffelen 2 seprate querys seams reasonable but it brings up other issues with the second query as now with the code below i can get the documents_id from the user and then do a query on the products and everything looks ok so i think i am going in the correct direction as i can print the id of the document in the loop to ensure i am accessing the correct ones but when i change this to get a snapshot of the document i cant access the data within this is probably me doing something silly or misunderstanding something but this feels very awkward compared to sql when trying to get and work with the data. For example if i return the data it wants it to be in the form of a future> however once i return the data in that format then i can no longer access the id's in the same way as i was doing.</p>
  
  <pre><code>Future&lt;List&lt;DocumentSnapshot&gt;&gt; getSeedID() async{
      var data = await Firestore.instance.collection('users').document(widget.userId).collection('products').getDocuments();
      var productList = data.documents;
      print("Data length: ${productList.length}");
      for(int i = 0; i &lt; productList.length; i++){
        var productId = Firestore.instance.collection('products').document(productList[i]['productId']).documentID;
        if(productId != null) {
          print("Data: " + productId);
        }
      }
      return productList;
    }
  </code></pre>