0

I'm using Firebase. Where I need to fetch the record for a particular attribute. But when I have used the Firebase query method, I'm unable to get the actual result. Following is my code:

Firebase ref = ZopOrderingAplication.getFirebaseInstance();
Firebase retailerMastRef = ref.child("Retailer_Master");

Here s the query I'm using:

Query queryRef = retailerMastRef.orderByChild("user_name").equalTo("8105409301","user_name");

Here is the function I'm using to fetch the records:

queryRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                long getChildCount = dataSnapshot.getChildrenCount();
                Log.i(TAG,"getChildCount: "+getChildCount);

                //Retailer_Master retailerObj = dataSnapshot.getValue(Retailer_Master.class);

                //Log.i(TAG,"retailer phone queryRef: "+retailerObj.getPhone());
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });

Here is the data in my firebase databse: enter image description here

AL.
  • 36,815
  • 10
  • 142
  • 281
Seenu69
  • 1,041
  • 2
  • 15
  • 33
  • You've included a picture of the JSON tree in your question. Please replace that with the actual JSON as text, which you can easily get by clicking the Export button in your Firebase Database console. Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. – Frank van Puffelen Sep 28 '16 at 13:59
  • @FrankvanPuffelen thanks for suggestion. will replace it. – Seenu69 Sep 29 '16 at 06:35

1 Answers1

1

I think you need to try this:

Query queryRef = retailerMastRef.orderByChild("user_name").equalTo("8105409301");

Remove user_name from equalTo() as you have it in orderByChild.

Hope this helps. Do let me know if it changes anything for you.

Nishant Dubey
  • 2,802
  • 1
  • 13
  • 18
  • Yes that is working but is there any groupby option to fetch only original records instead of fetching the duplicate records? – Seenu69 Sep 29 '16 at 06:34
  • Please give me an example that explains your issue or share a json. What do you mean by original records ?What will be the property of original records ? Give me something more to help you properly . – Nishant Dubey Sep 29 '16 at 08:02