Kaushal Topinkatti
Kaushal Topinkatti

Reputation: 304

How to get rid of automatic generated ID firebase database?

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?

Upvotes: 3

Views: 3847

Answers (3)

niko
niko

Reputation: 5281

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"

Upvotes: 0

Brij
Brij

Reputation: 43

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!

Upvotes: 0

Alex Mamo
Alex Mamo

Reputation: 139019

That id is not an automatic generated ID is an id that is pushed by the push() method. To get rid of that, you need not to use the push method. You need to change this line of code:

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

with

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

Upvotes: 3

Related Questions