I want to iterate a collection which starts at collection document ID.
有没有像下面这样的方法可以让我们从 id 或属性 id 开始读取数据?
db.collection("questions").startReadingDocumentAt("02cubnmO1wqyz6yKg571 ").limit(10).get()
或
db.collection("questions").startReadingWhereEqualTo("questionID","02cubnmO1wqyz6yKg571 ").limit(10).get()
我知道我可以根据 Id 读取 DocumentSnapShot,然后可以开始迭代 lastVisible 项。但它花了我两次读取操作。能不能一次搞定。
Firestore-root
|
--- questions (collections)
| |
| --- 02cubnmO1wqyz6yKg571 (questionId document) // myID and my questionID is same
| |
| --- questionId: "02cubnmO1wqyz6yKg571"
| |
| --- title: "Question Title"
| |
| --- date: August 27, 2018 at 6:16:58 PM UTC+3
| |
我已经走了through this
解释
我不想做 RecyclerView 分页
。我想在每次 Activity 开始时加载下 10 个问题。所以我以相同的方式调用查询,但它要求我保存 DocumentSnapShot。所以我决定保存questionID并以此为基础读取数据...
最佳答案
没有:
startReadingDocumentAt("02cubnmO1wqyz6yKg571")
也不
startReadingWhereEqualTo("questionID","02cubnmO1wqyz6yKg571")
在 firestore 中,但根据您的数据库架构,要解决此问题,您可以使用以下查询:
db.collection("questions").
whereGreaterThanOrEqualTo("questionID","02cubnmO1wqyz6yKg571")
.limit(10)
.get()
addOnCompleteListener.(/* ... */)
更多信息here :
Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than or equal to the specified value.
关于java - 根据 ID 或属性迭代 Firestore Android 集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52069594/