代码之家  ›  专栏  ›  技术社区  ›  Zar E Ahmer

基于ID或属性迭代Firestore Android集合

  •  1
  • Zar E Ahmer  · 技术社区  · 6 年前

    我想迭代一个从集合文档ID开始的集合。

    有没有像下面这样的方法让我们从id或属性id开始读取数据?

     db.collection("questions").startReadingDocumentAt("02cubnmO1wqyz6yKg571 ").limit(10).get() 
    

    db.collection("questions").startReadingWhereEqualTo("questionID","02cubnmO1wqyz6yKg571 ").limit(10).get()
    

    我知道我可以根据身份证看那个文件 然后可以开始迭代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 pagination . 我想 加载下10个问题 文档快照 . 所以我决定保存questionID并根据它读取数据。。。

    2 回复  |  直到 6 年前
        1
  •  1
  •   Alex Mamo    6 年前

    没有:

    startReadingDocumentAt("02cubnmO1wqyz6yKg571")
    

    也不是

    startReadingWhereEqualTo("questionID","02cubnmO1wqyz6yKg571")
    

    在firestore中,但根据您的数据库模式,要解决此问题,可以使用以下查询:

    db.collection("questions").
        whereGreaterThanOrEqualTo("questionID","02cubnmO1wqyz6yKg571")
        .limit(10)
        .get()
        addOnCompleteListener.(/* ... */)
    

    更多信息 here :

    创建并返回一个带有附加筛选器的新查询,该筛选器要求文档必须包含指定的字段,并且该值应大于或等于指定的值。

        2
  •  1
  •   Michael Lehenbauer    6 年前

    query cursors . 例如。:

    db.collection("questions")
        .orderBy("questionID")
        .startAt("02cubnmO1wqyz6yKg571")
        .limit(10)
        .get()