Firebase在Android中查询数组索引值

时间:2018-03-19 03:12:42

标签: android firebase firebase-realtime-database

如何列出recent members索引等于0的所有"5"

1 个答案:

答案 0 :(得分:1)

这样的事情应该有效:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference("recent");
Query query = ref.orderByChild("members/0").equalTo("5");
query.addValueListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
            System.out.println(childSnapshot.getKey());
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {            
        throw databaseError.toException());
    }
});

这里的诀窍是,您要在orderByChild()中为要订购/过滤的属性指定相对路径