如何在Firestore文档的字段中搜索

Rez*_*rim 4 android google-cloud-firestore

如何搜索消防站文件?如果Firestore集合包含某些文档,并且文档中有一个名为“ title”的字符串字段。如何使用Firebase Android API搜索特定标题。

Jon*_*ate 5

它在文档记录在这里,在页面的最后一节,标题为获取从集合多个文档

Firestore提供了whereEqualTo查询数据的功能。

示例代码(来自文档):

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());
                }
            }
        });
Run Code Online (Sandbox Code Playgroud)