我正在尝试使用密钥检查Firebase节点是否存在。例如。我正在查看节点“ child_value”是否作为“ parent_value”的子代存在。
例如
我的数据库引用指向“ parent_value”。
语句.child("child_value")
返回the node of the child value
语句.hasChild("child_value")
返回False
当子节点确实存在时,检查.haschild()返回False的原因可能是什么导致这种奇怪的行为?
EDIT :代码段
//Entire code block below is inside of another singlevaluevent listener, don't know if that would cause any problems
DatabaseReference ref = FirebaseDatabase.getInstance().getReference()
.child("Values");
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull Datasnapshot dataSnapshot){
if(dataSnapshot.hasChild(key) {
//Would expect the flow to end up here since the child exists
}
else {
//Flow ends up here
}
}