base上查询不适用于带有字符串子字段的orderByChild

base上查询不适用于带有字符串子字段的orderByChild

本文介绍了在Firebase上查询不适用于带有字符串子字段的orderByChild/equalTo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不明白这一点,再一次,我几乎绝望地处理了火力基地.

I really don't get this and, once more, am close to desperation dealing with firebase..

我有一个保存在特定位置的列表:root/Chats/WPXEmqvX1BfQB9n3UQFjF3xi1so2

I have a list saved at a specific location: root/Chats/WPXEmqvX1BfQB9n3UQFjF3xi1so2

    "Chats" : {
    "Jc9dASQdabXiT0holYFDkeqCczK2" : {
      "-L18x_ytEW0vEh5PpMWt" : {
        "deleted" : false,
        "lastMessage" : "Yes, we can meet on thursday",
        "nick" : "Hugo",
        "uid" : "WPXEmqvX1BfQB9n3UQFjF3xi1so2",
        "userType" : 0
      }
    },
    "WPXEmqvX1BfQB9n3UQFjF3xi1so2" : {
      "-L18x_ys4_VF-zSDDk8J" : {
        "deleted" : false,
        "lastMessage" : "Yes, we can meet on thursday",
        "nick" : "SABINE",
        "uid" : "Jc9dASQdabXiT0holYFDkeqCczK2",
        "userType" : 1
      },
      "-L18x_z5trZFItxd08XI" : {
        "deleted" : false,
        "lastMessage" : "I´m fine, thanks, how are you?",
        "nick" : "Melanie",
        "uid" : "qTmcljT8YAYf2TpnxX1LCopdXde2",
        "userType" : 1
      }
    },
    "qTmcljT8YAYf2TpnxX1LCopdXde2" : {
      "-L18x_z5trZFItxd08XJ" : {
        "deleted" : false,
        "lastMessage" : "I´m fine, thanks, how are you?",
        "nick" : "Hugo",
        "uid" : "WPXEmqvX1BfQB9n3UQFjF3xi1so2",
        "userType" : 0
      }
    }
  }

我要检查列表中是否包含具有特定uid的条目,

I want to check if the list contains an entry with a specific uid with

rootRef.child("Chats").child("WPXEmqvX1BfQB9n3UQFjF3xi1so2")
.orderByChild("uid").equalTo("Jc9dASQdabXiT0holYFDkeqCczK2")
.addListenerForSingleValueEvent

处理程序:

    rootRef.child("Chats").child("WPXEmqvX1BfQB9n3UQFjF3xi1so2")
                    .orderByChild("uid").equalTo("Jc9dASQdabXiT0holYFDkeqCczK2")
                    .addListenerForSingleValueEvent(object : ValueEventListenerAdapter(){
                        override fun onDataChange(data: DataSnapshot?) {

                        }
                    })

    open class ValueEventListenerAdapter : ValueEventListener {
    override fun onDataChange(data: DataSnapshot?) {}
    override fun onCancelled(error: DatabaseError?) {
        throw DbFailureException(if (error != null) error.message else "Unknown reason")
    }
}

我在onDataChange方法中收到的DataSnapShot对象为空,未找到任何内容.为什么?它适用于布尔字段,例如.orderByChild("deleted").equalTo(false),但不适用于字符串字段.与其他字符串字段的情况相同.还可以有人解释一下为什么在Firebase上进行的这种数据查询如此复杂,为什么每个查询都需要花费数小时的研究来弄清楚该怎么做?

The DataSnapShot object I receive in the onDataChange method is empty, nothing found. Why? It's working with the boolean fields, like .orderByChild("deleted").equalTo(false), just not with the string fields. Same situation with the other string fields.Can also somebody please explain why this data querying at firebase is so ridiculously complicated and each query takes hours of research to find out how it has to be done?

推荐答案

在保存特定节点时,您无法更新同一节点.为什么,因为它仍在使用并保留参考.

When you are holding particular node you can't update the same node. Why because it's still in use and holding reference.

这篇关于在Firebase上查询不适用于带有字符串子字段的orderByChild/equalTo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 18:08