Reputation: 827
I am trying to add data to Firebase in this structure from android application:
UserID: {
uniqueId: {
Data1: ""
Data1: ""
}
uniqueId: {
Data2: ""
Data2: ""
}
}
But I am struggling to get the UserID working with the uniqueID, can someone please help;
DatabaseReference mypostref = databaseReference.push();
databaseReference.child(user.getUid()).setValue(Personname: "Data", personaddress: "Data");
I have managed to (I think) get hold of the unique id through creating this: mypostref but how do I join the two together? Own its on the below code works fine but its only with the Uid. I want to break it further down so it has unique ID for each data set.
databaseReference.child(user.getUid()).setValue(Friend1Name: "Data", Friend1Address: "Data");
Please let me know if my question is not clear. Thanks.
Upvotes: 2
Views: 1566
Reputation: 1840
Try this:
DatabaseReference parentUserNode = databaseReference.child(user.getUid);
//Edit: Added way of saving the key generated by push
String keyFromPush = parentUserNode.push().getKey();
parentUserNode.child(keyFromPush).setValue(/*Add whatever value you want in here*/).
This will create a node like this:
uid: {
uniqueid01: {
...
}
uniqueid02: {
...
}
}
Hope this helps.
Upvotes: 3