Reputation: 11
I'm trying to get a value from my firestore with flutter. I have the collection users and all of them has attributes like auth
, email
, nickname
.
I'm trying to get a function where I send the email of a user, the function loops through all the users and gives me back the nickname of the user that has that email.
any help please?
Update**************************************************** StreamBuilder
So i got this out of a streamBuilder and my getNick function is this
And this is the output
Upvotes: 0
Views: 1558
Reputation: 3371
One of the handy features of firestore is that you don't need to loop through each document in a collection to get one with a particular value. This is because of how firestore is efficiently indexing your collections behind the scenes so that you can easily retrieve a single document or collection of documents according to some condition on what the document contains.
You can use the .where(field, isEqualTo: value) method on a collection reference to get a query, and then call the async method .getDocuments() on the filtered query and wait for firestore to give you the documents. You will only be billed for the one database read operation if you are just getting a single document that way.
Upvotes: 3
Reputation: 877
You can get a User object using query operators and then get another attribure of that user.
Upvotes: 0