How to display content of every node using one node in Firebase? - android

I have the following structure saved in my database:
What I want is I want the databaseReference to recognise the entire node using only the unique imageUIDh and display the content of all fields like postedAtTime, postedOnDate etc.
Is this possible in Firebase? Is there some alternative to achieve what I want?
Please let me know.

You can use Query
ref = FirebaseDatabase.getInstance().getReference();
ref.orderByChild("imageUIDh").equalTo(imageUIDh).addValueEventListener(valueEventListener);
Hope this helps :)

Related

How to get just one child from FIrebase Realtime Database instead of whole list

I am implementing Firebase Realtime Database for my app.
The database contains a lot of entries that will continue to grow in the future.
I want to retrieve only a specific child from the database, but i can't find any implementation for doing that.
In Firebase too the implementation retrieves all the entries from the database.
This will be cumbersome in the future.
Is there any way to retrieve only specific entries or just one entry(depending upon the customisation)?
Please help.
#ALex Mamo: This is the database image
Perhaps you are refering to shallow query, which only read the first child ? In this case you might want to look at the API implementation as mentioned here:
Firebase (2016) Shallow Query
There are two different ways of getting it. You'll have to change 'messages' to the name of your database. Replace PostTitle with the specific data you're trying to receive.
var rootRef = firebase.database().ref().child("messages");
rootRef.on("child_added", snap=> {
var postTitle = snap.child("PostTitle").val();
or
exports.sendPushNotification = functions.database.ref('/messages/{id}').onWrite((change, context) => {
const afterData = change.after.val();
const postTitle = afterData.PostTitle;
if you want retrieve few records this might help. as per image structure attached.
you can restructure the data, and use set method with keys as 0,1,2.... instead of "LK34h...."->0 .
use set method and store latest index value.
you retrive like this
firebase.database().ref().child('users_Post/0').on('value',sn=>{ console.log(sn.val())//use sn.val() })

how to get the Uid inside a child and another push ID child

this the structure of my firebase database and as you can see there is Uid inside the random ID under comments chile. can someone help me how to get that Uid
The first thing I really don't understand your question try to explain it in detail.
DatabaseReference myRef = database.getReference("Comments");
You can get references of your comments by above line and addValueEventListener to it. By doing this you will get all the data available in your comments. After that, you just have to filter your data if you need a particular UUID.

How do I get the key of this level?

Hi,
I have this problem in query in Firebase. The orderbykey() and orderbychild() doesn't work. How do I query this one?
cheers, thanks in advance.
Code Snippet:
Query mRef = mRootRef.child("Messages").orderByKey().equalTo(mAuth.getCurrentUser().getUid());
Query mRef = mRootRef.child("Messages").orderByChild("commWith").equalTo(mAuth.getCurrentUser().getUid());
i have just re design my JSON at firebase like in the image below, so that i could simply get the unique keys per data

Firebase return position in list

In my application I am storing the leaders where basically they are having some amount of points for completing the tasks. I am able to display them in recycle view based on their score. But Ideally I would need to show for the user in which position he sits ( 1st 2nd 3rd etc.) What would be a most efficient way to do so. Thank you in advance.
The best way to archive this it to order by the Score property:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
Query query = rootRef.child("Leaders").orderByKey("Score");
Please also take a look on official Firebase official documentation.

Android Firebase - Adding Values To Users

I am making an Android app with Firebase and I want to add sections to each FirebaseUser (like wins and losses) but I don't think you can add to those objects. Should I just use the Realtime Database to do this or is there a better way?
Thanks in advance!
DatabaseReference ref1= FirebaseDatabase.getInstance().getReference();
DatabaseReference ref2,ref3;
ref2= ref1.child(user);//user is the name of user
ref2.child("Wins").setValue(""what he won);
ref2.child("Loose").setValue(""what he Lose);
Here I created a child to root node with user name, added sub children(Win & Lose) to user and then I set values to these children.
And you can retrieve that data too based on your query.
Refer following link once.
https://firebase.google.com/docs/database/android/start/

Categories

Resources