Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value of some field in firebase firestore android?

Like upper question, i want to get value of some field in firebase firestore instead of all document with DocumentSnapshot

like this in SQL SELECT col_1, col_2, col_3 FROM table_name

How can i do it?

Thank you for the help.

like image 763
gnùhp gnắhT Avatar asked Nov 24 '17 08:11

gnùhp gnắhT


People also ask

How do I get value from firestore?

There are two ways for retrieving data, which is stored in Cloud Firestore. Calling a method to get the data. Setting a listener for receiving data changes events. We send an initial snapshot of the data, and then another snapshot is sent when the document changes.

How do I query multiple values in firestore?

Starting with… in queries! With the in query, you can query a specific field for multiple values (up to 10) in a single query. You do this by passing a list containing all the values you want to search for, and Cloud Firestore will match any document whose field equals one of those values.


1 Answers

The Cloud Firestore client-side SDKs always read and returns full documents. There is no way to read a subset of the fields in a document.

You can retrieve the entire document, and then process the DocumentSnapshot to just use the fields you're interested. But this means you're using more bandwidth than needed. If this is a regular occurrence for your app, consider creating a secondary collection where each document contains just the fields you're interested in.

Also see Doug's answer here (for Swift): How to access a specific field from Cloud FireStore Firebase in Swift

like image 180
Frank van Puffelen Avatar answered Nov 15 '22 22:11

Frank van Puffelen