这是数据库的结构
我需要获取" QNGGvYL7dgde9Oypi9a4IFdAys03"
的所有值我已经尝试过这段代码,但它无效
String uid = FirebaseAuth.getInstance().getUid();
DatabaseReference databaseRef = FirebaseDatabase.getInstance().getReference();
Query query = databaseRef.child("bookmarks").equalTo(FirebaseAuth.getInstance().getUid());
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
vehicleList.add(postSnapshot.getValue().toString());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
答案 0 :(得分:1)
如果您知道要获得的密钥,则不需要查询:
DatabaseReference ref = databaseRef.child("bookmarks").child(FirebaseAuth.getInstance().getUid());
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
vehicleList.add(postSnapshot.getValue().toString());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException(); // don't ignore errorrs
}
});