如何在Firestore文档的字段中搜索 [英] how to search at firestore document's field
本文介绍了如何在Firestore文档的字段中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何搜索Firestore文档?如果Firestore集合包含某些文档,并且文档中有一个名为"title"的字符串字段.如何使用Firebase Android API搜索特定标题.
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.
推荐答案
该文档记录在文档此处,在页面最后部分的标题为从集合中获取多个文档.
It is documented in the Docs here, in the last section of the page, titled Get multiple documents from a collection.
Firestore提供了 whereEqualTo
函数来查询您的数据.
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());
}
}
});
这篇关于如何在Firestore文档的字段中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文