1
votes

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:

Kullanıcılar(Users) enter image description here

Ürünler(Products)

enter image description here

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?

1
You can add more code related to your pages and models. I think you need to send a new request for each user to get their collection properties. - Akif
Please edit the question to show more clearly the code of the query that isn't working the way you expect. But I can tell you right now that one query can only access documents in one collection, and you won't be able to reach into another collection other than the one you first queried. If you want data from two collections, you will need two queries. - Doug Stevenson
So you say i can't use cloud firestore for getting nested documents, i need seperate 2 queries ? - Emir Kutlugün
Correct, you need separate queries for nested documents. You should know that firestore does NOT actually nest documents; it's more an addressing 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. - LeadDreamer

1 Answers

1
votes

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.