Reputation: 73
I have 2 collections in cloud firestore and want to use both of them trough one field of my product 'userBids' which I'm using document reference:
Ürünler(Products)
Problem I want to reach my user from my 'userBids' field in my product model, but getting error below;
Class 'DocumentReference' has no instance method '[]'.
Receiver: Instance of 'DocumentReference'
Tried calling: )
Text(data[0]['userBids'][index]['user']['nickname']
So how can I reach one collection from another collection in Cloud Firestore in Flutter?
Upvotes: 1
Views: 325
Reputation: 3499
You need separate queries for "nested" documents. You should know that firestore does NOT actually nest documents; it's more an addressing/indexing convention than anything else. A "child" document can exist without any parent collection or document; it is perfectly valid for your database to have a document like:
.doc("collection1/document1/collection2/document2/collection3/document3")
without any of collection1, document1, collection2, or document2 ever existing. In the Firebase Console you'll see the names and ID's of these non-existant collections & documents in italics.
Upvotes: 1