Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to search at firestore document's field

How to search at firestore documents? if firestore collection contains certain document and if there has a string field at document named 'title'. How can i search specific title using firebase android api.

like image 619
Rezaul Karim Avatar asked Oct 22 '17 17:10

Rezaul Karim


People also ask

How do I get data from QueryDocumentSnapshot?

A QueryDocumentSnapshot contains data read from a document in your Cloud Firestore database as part of a query. The document is guaranteed to exist and its data can be extracted using the getData() or the various get() methods in DocumentSnapshot (such as get(String) ).


1 Answers

It is documented in the Docs here, in the last section of the page, titled Get multiple documents from a collection.

Firestore provides a whereEqualTo function to query your data.

Example code (from Docs):

db.collection("cities")
        .whereEqualTo("capital", true) // <-- This line
        .get()
        .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()) {
                    for (DocumentSnapshot document : task.getResult()) {
                        Log.d(TAG, document.getId() + " => " + document.getData());
                    }
                } else {
                    Log.d(TAG, "Error getting documents: ", task.getException());
                }
            }
        });
like image 131
JonZarate Avatar answered Oct 05 '22 10:10

JonZarate