Thudner
Thudner

Reputation: 1169

Firebase Realtime Database: Listen to changes with specific values

I have the following DB structure:

 Users
     Test
          ID:1
          category:2
     Test1
         ID:2
         category:3
     Test3: 
         ID:3 
         category:2

Now I want to listen to any changes on Users child that only have category value 2.

How I can do that in Firebase.

Upvotes: 3

Views: 1071

Answers (1)

Ticherhaz FreePalestine
Ticherhaz FreePalestine

Reputation: 2377

as David Ibrahim says, you can use query to listen changes for the category with that value 2. You can something like this.

Query queryCategory = FirebaseDatabase.getInstance().getReference().child("Users").orderByChild("category").equalTo(2);
        queryCategory.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });

Upvotes: 1

Related Questions