我正在尝试列出与 ArrayList 中的字段字符串值相匹配的文档。
简单地:
- 我有带有在运行时存储的标签的 ArrayList
- 和带有字段标签 的文档
我想查询与存储在 ArrayList 中的标签之一相匹配的文档。这可以通过官方查询实现,还是我必须下载所有文档并在客户端进行过滤?感谢您的回答。
此外,这是我生成查询的方法:
public static Query getQueryForFollowed(DocumentSnapshot snapshots) {
if (snapshots == null || !snapshots.exists()) {
return FirebaseFirestore.getInstance().collection("posts").whereEqualTo("null", "null"); // return query that will get nothing
}
ArrayList<String> f = processFollowedTags(snapshots);
Query query = FirebaseFirestore.getInstance()
.collection("posts")
.whereEqualTo("tag", f.get(0));
for (int i = 1; i < f.size(); i++) {
query = query.whereEqualTo("tag", f.get(i));
}
return query;
}
我已调试代码,查询已包含请求的条件,但查询未找到任何匹配它的文档。
最佳答案
试试这个
Query query = FirebaseFirestore.getInstance()
.collection("posts")
.whereEqualTo("tag", f.get(0)).orderBy("tag", Query.Direction.ASCENDING);;
关于android - Firestore whereEqualsTo 来自 arraylist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51104856/