How to get rid of automatic generated ID firebase database?

Viewed 3424

Hi am new to android firebase and am stuck in middle the problem is when I push new data to database, am getting a new ID as root of one of the child. enter image description here

In the screenshot there is a ID below clinic, i want to get rid of it enter image description here

I want my data to get added in this manner, like every time when I add new clinic it should get added below general.

myRef = FirebaseDatabase.getInstance().getReference().child("clinic").push();

I have just attached push() at the end of my database reference.

myRef.child(typ).child(userID).child("clinic_name").setValue(name);

myRef.child(typ).child(userID).child("total_docs").setValue(total_docs);

myRef.child(typ).child(userID).child("working_hrs").setValue(clinic_wrk_hrs);

And in this way I am adding data to data. The only thing I want is get rid of that weird looking extra ID. How I do it?

3 Answers

To remove the autogenerated key just remove the push command..like below

mRef=FirebaseDatabase.getInstance().getReference("clinic");
mRef.child("timestamp").setValue(clinic_address);
mRef.child("timestamp").setValue(clinic_name);

If it worked let me know!

Better late than never:

I was facing the same issue and I believe what you want to use is child.update or child.set as opposed to child.push.

Here is an example using the Python SDK firebase_admin

root = db.reference(path='/', app=app)  # app was previously created

# PUSH
root.child(test).push({'name': 'John'})
# Will create something like
# ./
# |--test
# |------FIREBASE_ID
# |-----------------name: "John"

# UPDATE / SET
root.child(test).update({'name': 'John'})  # or .set({...})
# Will create something like
# ./
# |--test
# |------name: "John"
Related