Solution 1 :
I have tried the push() method but it generates different unique ids.
That’s expected behavior since calling push()
multiple times, will always generate each time a new random id.
Will I have to use FirebaseAuth to make the unique id similar for “user data” & “user key”.
When it comes to users IDs, yes, the most appropriate solution is to implement Firebase Authentication and use the UID
that is generated in this process. In the end, you can simply use the same UID
, in every reference that you need, for example:
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference userDataRef = rootRef.child("userData").child(uid); //One reference
userDataRef.setvalue(yourObject);
DatabaseReference otherUserDataRef = rootRef.child("otherUserData").child(uid); //Second reference
otherUserDataRef.setvalue(otherObject);
Problem :
Suppose there are two nodes:
-
user data (inside “user data” we have:)
unique id
name: “abc”
latitude: “123”
longitude: “456” -
user key (inside “user key” we have:)
unique id
g: “awe46q”
l
0:123
1:456
Here I want to save both “user data” & “user key” with the same unique id. But I don’t know how to do it.
Comments
Comment posted by Alex Mamo
What have you tried so far?
Comment posted by Bikram Khanikar
I have tried the push() method but it generates different unique ids. Will I have to use FirebaseAuth to make the unique id similar for “user data” & “user key”.
Comment posted by Bikram Khanikar
I tired out this and it was successfully saving “user data” & “user key” with same unique id(
Comment posted by Alex Mamo
Good to hear that 🙂 The
Comment posted by Bikram Khanikar
Thanks it is retrieving all data from
Comment posted by Alex Mamo
This is basically another question. In order to follow the rules of this community, please post another fresh question, so I and other Firebase developers can help you.
Comment posted by Bikram Khanikar
For sure Alex Mamo 🙂