Joe Horn
Joe Horn

Reputation: 21

Firebase flat database update method

My firebase database is below. I’m having a hard time understanding how to access the properties, (ie. address) for a specific record so I can update it. I’ve been pushing the data as items are added. So should I be storing the id along with my data so I can use it?

image of firebase data

Upvotes: 1

Views: 67

Answers (2)

Joe Horn
Joe Horn

Reputation: 21

This is what I used that ended up working.

mMessagesDatabaseReference = firebaseRef.child(dbItemKey).child("status");
    mMessagesDatabaseReference.set( document.getElementById("userName").innerHTML)

Where dbItemKey = the unique key assigned to the parent, "status" being the child element I wanted to update. "userName" being the variable I pushed into the child element.

I also use .set() because I wasn't worried about overwriting the data in the specific child.

The actual implementation is not so good as I'm using this as a quick test of firebase and its usage.

The one thing I did learn was there is a small chance that the random Id firebase gives could be a duplicate as its a timestamp and random numbers put together.

Upvotes: 0

chunkydonuts21
chunkydonuts21

Reputation: 79

 private FirebaseDatabase mFirebaseDatabase;

private DatabaseReference mMessagesDatabaseReference;

mFirebaseDatabase = FirebaseDatabase.getInstance();

//change your variable to something easy to read like info

mMessagesDatabaseReference = mFirebaseDatabase.getReference().child("info").child("address");
mMessagesDatabaseReference.push().setValue("set_your_updated_value_here");

Upvotes: 2

Related Questions