我尝试在Firebase中执行联接查询,但是代码未返回任何内容。场景是我需要在牌照后面找到要搜索的用户phoneNumber。我尝试了以下方法,但没有成功。 我从数据库中附加了代码和json文件。 谢谢
我正在尝试此解决方案,但没有成功How to perform join query in Firebase?
databaseReference.child("cars").child("User"+text.toUpperCase()).orderByChild("licenceNumber").equalTo(text.toUpperCase()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot postSnapshot : dataSnapshot.getChildren())
{
final Car carNumber = postSnapshot.getValue(Car.class);
String UID = carNumber.getId();
databaseReference.child("Users").child(UID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
final User user = postSnapshot.getValue(User.class);
String phone = user.getPhoneNumber();
textView2.setText(phone);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
{
"Users" : {
"1HvAKvh9AETSFYMTqbOIq6AlKap2" : {
"email" : "bb@ll.com",
"name" : "John",
"phoneNumber" : "1111"
},
"8RxAsvjDMhTugZtbm8etoxcJ6Ts1" : {
"email" : "nnn@gmail.com",
"name" : "Jane Doe",
"phoneNumber" : "123456789"
},
"MuM99wZYuhbpbXxcv3wXxy9IGqh2" : {
"email" : "Fff@mail.com",
"id" : "MuM99wZYuhbpbXxcv3wXxy9IGqh2",
"name" : "Violeta",
"phoneNumber" : "1234"
},
"Np1jymmdVpMi3hqKDrTPdYuSR9g2" : {
"email" : "ddd@fff.com",
"id" : "Np1jymmdVpMi3hqKDrTPdYuSR9g2",
"name" : "Henry",
"phoneNumber" : "12345"
},
"PFalUadu8xf46siLWikQLLeK7L92" : {
"email" : "Hjjj@hhhh.com",
"id" : "PFalUadu8xf46siLWikQLLeK7L92",
"name" : "George",
"phoneNumber" : "077292"
}
},
"cars" : {
"1HvAKvh9AETSFYMTqbOIq6AlKap2" : {
"UserAR99KTA" : {
"id" : "1HvAKvh9AETSFYMTqbOIq6AlKap2",
"licenceNumber" : "AR99KTA"
}
},
"8RxAsvjDMhTugZtbm8etoxcJ6Ts1" : {
"UserGG77HHH" : {
"id" : "8RxAsvjDMhTugZtbm8etoxcJ6Ts1",
"licenceNumber" : "GG77HHH"
},
"UserHHHVVFF" : {
"id" : "8RxAsvjDMhTugZtbm8etoxcJ6Ts1",
"licenceNumber" : "HHHVVFF"
},
"UserSV07WNE" : {
"id" : "8RxAsvjDMhTugZtbm8etoxcJ6Ts1",
"licenceNumber" : "UU07WUE"
}
}
}
}