java - 根据 ID 或属性迭代 Firestore Android 集合

标签 java android firebase pagination google-cloud-firestore

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/

相关文章:

java - 解析有效 JSON 时出现 Volley org.json.JSONException

c# - Firebase 3 : creating a custom authentication token using . 网络和 c#

java - 如何转储控制台登录文件

Java utils 类,静态方法与注入(inject) utils 类

java - 具有作为构造函数参数传递的通用基类的枚举

java - Apache-commons-net FTPClient storeUniqueFile 用法

android - 打开 pdf 阅读器后 LinearLayout 出现 NotSerializableException

android - 打开eclipse时出错

ios - 从 Firebase Swift 检索双数字时出现问题

javascript - 从 Firebase 数据库填充 Firebase Cloud Functions 中的数组