Reputation: 1326
I have the following structure in my Firebase Database JSON Tree:
Now I have the requests
node as the following in Android:
DatabaseReference requestsNode
How can I add another node request2
with all the information-childs (date, destination, origin, ...) to the requests
node? At the time of execution I do not know how many requests are already in the tree. So I do not know the increment request<number>
number.
Upvotes: 0
Views: 1870
Reputation: 7720
You can use push()
method to add new child instead of deciding the index for your child. It is based on timestamp so it will always unique and sorted chronologically.
So for your case
ref = FirebaseDatabase.getInstance().getReference("requests");
ref.push().setValue(requestObject);
Hope this helps, comment if you have questions :)
Upvotes: 2