【问题标题】:Can't get subcollection in Firestore - Kotlin无法在 Firestore 中获取子集合 - Kotlin
【发布时间】:2018-06-07 16:36:43
【问题描述】:

我正在做一个小测试应用程序,我正在尝试从市场上获取所有产品。

当前的数据库架构是:

markets:[
       market1: {}, 
       market2: {}, 
       market3: {
          name: "",
          products: [
               item1: {}, 
               item2: {}
          ]
       }
   ] 

我在 kotlin 中的代码是:

try {
     db.collection("markets").document(marketId).collection("products")
                .get()
                .addOnCompleteListener { task ->
                    if (task.isSuccessful) {

                        var products = mutableListOf<Product>()

                        for (document in task.result) {
                            products.add(
                                Product(
                                        document.id,
                                        document.get("name").toString(),
                                    true
                                )
                            )
                        }

                        //updateList(products)


                    } else {
                        Log.e("Getting markets", "Error getting documents.", task.exception)
                    }

                }
    }catch (e : Exception){ }

我还尝试将db.collection().document().collection() 替换为:

db.collection("markets/$marketId/products")

但它仍然返回 0 个项目,(有两个)。

任何帮助将不胜感激

【问题讨论】:

    标签: firebase kotlin google-cloud-firestore


    【解决方案1】:

    在我测试了很多变体之后,我注意到无论我输入什么集合,它都没有给我任何结果,即使是在其他活动中起作用的集合。

    于是我在手机上的应用管理器中清除缓存并删除数据,然后我再次打开,现在正在工作。

    【讨论】:

      猜你喜欢
      • 2021-05-07
      • 1970-01-01
      • 2019-02-17
      • 2020-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-08
      • 2019-04-30
      相关资源
      最近更新 更多