【问题标题】:Query (Sort) field Firestore KOTLIN查询(排序)字段 Firestore KOTLIN
【发布时间】:2020-05-21 10:50:59
【问题描述】:

我尝试通过从微调器输入一个值来查询(排序)我在 Firestore 中的一个字段,但我没有让它工作。我应该使用“whereEqualTo”还是“orderBy”?

这是我的代码:

        override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {

            firestoreDB.collection("posts")
                .whereEqualTo("genre", position)
                .get().addOnSuccessListener {
                    println(it.documents)
                }
            val type = parent?.getItemAtPosition(position).toString()
            Toast.makeText(activity,type, Toast.LENGTH_LONG).show()
        }

【问题讨论】:

标签: firebase kotlin google-cloud-firestore


【解决方案1】:

您应该使用orderBy,因为whereEqualTo 只返回"genre" 等于position 的文档。

【讨论】:

    猜你喜欢
    • 2018-05-12
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 2019-08-23
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 2018-04-14
    相关资源
    最近更新 更多