Reputation: 695
There are documents which includes user information.
"users" collection
|- "user1" doc
|- "name" : "John"
|- "age" : 20
|- "user2" doc
|- "name" : "Mike"
|- "age" : 30
|- "user3" doc
|- "name" : "Dave"
|- "age" : 20
|- "user4" doc
|- "name" : "Chen"
|- "age" : 25
What I want to do is getting names that have same age value. For example of above structure, when you want to get only 20 age, "John" and "Dave"'s documents returned.
Normally, you would get all the documents of "users" collection and choose them on the client, but this would waste Firebase's "Document reads" or help restrictions of network.
How can I make field selections on the Firebase side instead of on the client?
Upvotes: 0
Views: 38
Reputation: 598728
What you're looking for is a query. With this it'd look something like:
FirebaseFirestore.instance
.collection('users')
.where('age', isEqualTo: 20)
.get()
.then(...);
Also see the Firebase documentation on queries, which does not have Flutter/Dart examples but is more comprehensive aside from that.
Upvotes: 1