Firebase Query, equalTo()

993 views
Skip to first unread message

jagattele...@gmail.com

unread,
Feb 22, 2018, 10:23:18 AM2/22/18
to Firebase Google Group

Hi,

This is my Firebase Database and I'm developing an android application. Now in "Generated" node, I want to fetch only that child who's "userId" matches to current user's UID.

Now in below-given code, I'm using "equalTo()" to match the user id. But "equalTo()" is not giving the desired result when it uses a variable in it. Instead of that when I insert the user's UID manually (coping from Firebase console and pasting it into ".equalTo()" the given query works absolutely fine.   

firebaseAuth = FirebaseAuth.getInstance();
firebaseUser = firebaseAuth.getCurrentUser();
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference("Leads");
populatingGeneratedLeads = databaseReference.child("Generated").orderByChild("userId").equalTo(current_userid);
//Getting User UID
if (firebaseUser != null) {
current_userid = firebaseUser.getUid();
}

So can someone guide me how to insert a value in "equalsTo()" through a variable.

Samuel Stern

unread,
Feb 22, 2018, 11:28:08 AM2/22/18
to fireba...@googlegroups.com
Hi there,

This seems to be a problem in your code.  You're setting current_userid a few lines after you write the line containing your equalTo query.  You need to set the variable before, or it will be undefined.

- Sam

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/712fd4cd-f0cf-431b-b4d4-37ac3328744b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages