2

I'm trying to perform login operation in my app using firebase my Users node is something like:

my model

mUserCompounds.orderByChild("email").equalTo("test@gmail.com").addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        System.out.println(dataSnapshot.getChildrenCount());                        }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });

i want to get that complete object with which i have matched the name. so that

i can also compare password etc. Thanks for help.

Community
  • 1
  • 1
Nouman Ch
  • 4,023
  • 4
  • 29
  • 42
  • https://stackoverflow.com/questions/38017765/retrieving-child-value-firebase refer this – Gowthaman M Oct 01 '17 at 13:27
  • 2
    What is the problem with the code you shared? What does it do? What did you expect it to do? – Frank van Puffelen Oct 01 '17 at 15:10
  • dear i want to get the test object so that i can use image, pointsTotal and other values. All i know about User is his email and password on the basic of email and password i want to fetch complete object. – Nouman Ch Oct 01 '17 at 18:06
  • your question is not clear. Do you want to get the values of the node "test" in order to compare them with other values? – Lucem Oct 02 '17 at 11:28
  • @Lucem dear i have two values email and password on the basis of this info i want to get the complete record that is "test" node and all its child values. – Nouman Ch Oct 02 '17 at 12:56

3 Answers3

2

Visit the Firebase documentation enter link description here

read firebase data Also always push data to firebase with Pushkey so you can get whole object.

Nouman Ch
  • 4,023
  • 4
  • 29
  • 42
  • i have a key named as test under Users node. – Nouman Ch Oct 01 '17 at 17:59
  • No you have to push object using push key. – Jawad Hassan Soomro Oct 02 '17 at 18:54
  • code example : `DatabaseReference postsRef = ref.child("posts"); DatabaseReference newPostRef = postsRef.push(); newPostRef.setValue(new Post("gracehop", "Announcing COBOL, a New Programming Language")); // We can also chain the two calls together postsRef.push().setValue(new Post("alanisawesome", "The Turing Machine"));` – Jawad Hassan Soomro Oct 02 '17 at 19:00
1

this is pretty simple

mUserCompounds.orderByChild("email").equalTo("test@gmail.com").addValueEventListener(new ValueEventListener() {
                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {

                        Log.i("your tag",""+dataSnapshot.toString());
    }

                        @Override
                        public void onCancelled(DatabaseError databaseError) {

                        }
                    });
Nomi
  • 1,981
  • 2
  • 8
  • 10
1

First make a pojo class of User data .

Class User {
 String about;
 String email;
 String image;
 String name;
 String password;
 String pointsTotal;
 String totalTasksDone;
}

Make getter setters and define constructors.

mUserCompounds.orderByChild("email").equalTo("test@gmail.com").addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if (dataSnapshot.exists()) {
                         //User already exists
                         User user1 = dataSnapshot.getValue(User.class); 
                         System.out.println(user1.getPassword());
                       }
                  }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
HarshitG
  • 2,677
  • 3
  • 16
  • 13