0

Here I want to modify value of ADDRESS Field. Here the value 1R6RsMMgQ.... represents the uid of each user. Here I am able to reach upto userDetails but I am unable to go to address key for modifying the value. Here the -MXcKsJV... value is the array key value which is generated at the time of pushing the value to database using the push() method.

I tried to update the value by writing this query

firebase.database().ref(`/user/${uid}/userDetails/`).update({address: 'change'})

By writing this query I would update the userDetails child but this would not been reflected in the array (i.e. -MXcKs... array)

Can anyone suggest me how to do this?

enter image description here

8
  • 1
    What is the meaning of the push key (-MXcK level in your database? Are you looking to store multiple addresses per user? If the answer to that is "yes", then which of the user's addresses are your looking to update? Commented Apr 8, 2021 at 14:20
  • Yes there will be multiple addresses per user and these address updation depends on users choice. Commented Apr 9, 2021 at 15:06
  • In that case: how can we know the user's choice? Do you have the -M... key they selected in a variable somewhere? Commented Apr 9, 2021 at 15:08
  • No, I haven't store that key in any variable Commented Apr 9, 2021 at 15:38
  • 1
    That's all fine, but we have no way with the code you shared to know which child node (-M...) to update. Commented Apr 9, 2021 at 17:40

1 Answer 1

1

Your ref is to /user/1R6.../userDetails/ and not /user/1R6.../userDetails/-MXcK... You have to update your ref or fix your data structure.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.