我正在尝试过滤并获取写入Firestore的文档。所以我里面的收藏还有一个哈希图
文档1
//.....
"votes": [
{
"userID1": true,
"userID2": true,
}],
//.....
文档2
//.....
"votes": [
{
"userID1": true,
"userID2": true,
}],
//......
请在这里查看我的 Firestore 快照以更好地理解
现在我需要过滤所有用户ID1(在附加图像中突出显示(其中等于true。
我尝试了以下代码似乎不起作用
// Construct query basic query
mQuery = mFirestore.collection(fsCollection)
.orderBy("timestamp", Query.Direction.DESCENDING)
.whereEqualTo(getUid(), true)
.limit(LIMIT);
您需要更改以下代码行:
mQuery = mFirestore.collection(fsCollection)
.orderBy("timestamp", Query.Direction.DESCENDING)
.whereEqualTo(getUid(), true)
.limit(LIMIT);
跟
mQuery = mFirestore.collection(fsCollection)
.orderBy("timestamp", Query.Direction.DESCENDING)
.whereEqualTo("votes." + getUid(), true) //Use the name of the HashMap
.limit(LIMIT);
由于在同一查询中使用orderBy
和whereEqualTo
方法,因此需要创建索引。在启动应用程序的那一刻,您将在日志猫中看到一个url
。单击该 URL 以创建所需的索引。