Data retrieving error while i want to get all child from a certain Key

Related searches

I want to read some specific child from the parent-child, by getchild() function but this will not work properly.

FirebaseUser FUser = mAuth.getCurrentUser();
            String userid = FUser.getUid();

            DatabaseReference DR;
            DR = FirebaseDatabase.getInstance().getReference().child("HistoryTable").child(userid);
            DR.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                   // Iterable<DataSnapshot> root = dataSnapshot.getChildren();
                  //  Toast.makeText(getApplicationContext(), "ds "+dataSnapshot.getChildren(),Toast.LENGTH_LONG).show();
                    for (DataSnapshot ds: dataSnapshot.getChildren()) {
                 //       Toast.makeText(getApplicationContext(), "ds "+ds,Toast.LENGTH_LONG).show();

                        for (DataSnapshot d: ds.getChildren()) {

                            String Height = d.getKey() + d.getValue() + "\n".toString();
                            String ch =  d.child("1Height:").getValue(String.class);

                           // tv.append(Height);
                            tv.append(ch);


                        }
                    }


                }

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

                }

            });

I want to get this four child from every key.

you have to add your push id in reference :-

DR = FirebaseDatabase.getInstance().getReference().child("HistoryTable").child(userid).child("push id");
            DR.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                   // Iterable<DataSnapshot> root = dataSnapshot.getChildren();
                  //  Toast.makeText(getApplicationContext(), "ds "+dataSnapshot.getChildren(),Toast.LENGTH_LONG).show();
                    for (DataSnapshot ds: dataSnapshot.getChildren()) {
                 //       Toast.makeText(getApplicationContext(), "ds "+ds,Toast.LENGTH_LONG).show();

                        for (DataSnapshot d: ds.getChildren()) {

                            String Height = d.getKey() + d.getValue() + "\n".toString();
                            String ch =  d.child("1Height:").getValue(String.class);

                           // tv.append(Height);
                            tv.append(ch);


                        }
                    }


                }

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

                }

            });

Retrieving Data, If you don't have a Unity project, you can download a sample app. Add the The task result will contain a snapshot containing all data at that location, including child data. OrderByChild(), Order results by the value of a specified child key. Calling an order-by method multiple times in the same query throws an error. When using orderBy with the name of a child key, data that contains the specified child key will be ordered as follows: Children with a null value for the specified child key come first. Children

Try like this if you just want to read the value. if you want to read data only once use addListenerForSingleValueEvent()

*Try to read values by object stucture https://firebase.google.com/docs/database/android/read-and-write#basic_write

DR.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                        for (DataSnapshot d: ds.getChildren()) {
                            //below line may cause null pointer Exception
                            String Height = d.getKey() + d.getValue() + "\n".toString();
                            if(d.child("1Height:").getValue()!=null){
                            String ch =  d.child("1Height:").getValue(String.class);
                            //tv.append(Height);
                            tv.append(ch);}
                            }
                       }
                  }

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

                }

            });

Retrieving Data, A snapshot is a picture of the data at a particular database reference at For ordering purposes, it is also passed a second argument containing the key of the previous child. If you want to retrieve only the data on each new post added to your The child_changed event is triggered any time a child node is� This code will take the name that you provide at the prompt and attempt to retrieve the age for that person. Whatever you type in at the prompt will be used as the key to the ages dictionary, on line 4.

To get the value of your 4UserId property, simply use the following lines of code:

String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference uidRef = rootRef.child("HistoryTable").child(uid);
ValueEventListener valueEventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        for(DataSnapshot ds : dataSnapshot.getChildren()) {
            String userId = ds.child("4UserId").getValue(String.class);
            Log.d(TAG, userId);
        }
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {
        Log.d(TAG, databaseError.getMessage()); //Don't ignore errors!
    }
};
uidRef.addListenerForSingleValueEvent(valueEventListener);

The result in your logcat will be:

2Wwrjx...P2obFO83

How To Query Arrays of Data in Firebase | by Justin Tulk, How To Retrieve Some Values From A Firebase Object But Not ALL The Values is an object that consists of key:value pairs of uniques:video-ids. by passing in an array, there's no way to do something like this to get all the return databaseRef.child('videos').child(id).on('value', s => s) handle error }). See the following screenshots: The code: Here, dbRef is the database reference to the parent node. The database structure: For each dbRef of different sports, I have a child node “contacts”.

Collection Queries with Firebase. Stop querying your entire Firebase , If you care to receive your data from Firebase in the specified order, make sure to So aggregated your children into an array manually, and you'll have ordered children! An orderBy* parameter is required for any query. It orders the ref's children by their keys, usually push keys — which order by time. Retrieving All Columns If you want to retrieve the data from every column in a table, you do not need to specify each column name after the SELECT keyword. Use the asterisk character (*) in place of a column list in a SELECT statement to instruct MySQL to return every column from the specified table.

Node.js v14.8.0 Documentation, First, make sure to have downloaded and installed Node.js. All errors thrown by the assert module will be instances of the AssertionError class. Deep equality means that the enumerable "own" properties of child objects are also This API retrieves data that was previously associated with the currently running Agent via� The ChildMoved event is triggered whenever the ChildChanged event is raised by an update that causes reordering of the child. It is used with data that is ordered with OrderByChild or OrderByValue.

If an entity has an alternate key defined, you can also use the alternate key to retrieve the entity instead of the unique identifier for the entity. For example, if the Contact entity has an alternate key definition that includes both the firstname and emailaddress1 properties, you can retrieve the contact using a query with data provided for

Comments
  • Hi Mostafijur! Have you tried my solution above, does it work?
  • "It doesn't work" doesn't help. Why do you say it doesn't work? What's the behavior? Do you have an error?
  • this occurs no error but can't retrieve expected data.
  • I this case, please add to your question the exact code that your are using to see where the problem is. Also is your onDataChange() even triggered?