I have a question regarding updating the key value. How can I achieve this?
Here is the data we are working with:
https://i.sstatic.net/3VYSg.png
Currently, I am using set() to write the data.
I want users to be able to edit their bookTitle
and have it reflect in both bookInfo
and books
. I attempted to use update() but faced some challenges. While I was able to edit the bookTitle
in bookInfo
, I couldn't do the same in books
.
Considering moving the data is not an option as it would erase bookData
. I also tried push(), however without the pushID, searching becomes difficult (particularly since users cannot have two books with the same name).
So, my query is: Is there a way to update the key value? Or perhaps there is a more efficient approach that could be suggested. All suggestions are welcome. Thank you!
Update: Below is what I am currently using to update the book title within bookInfo
:
var bookName = document.getElementById('bookName').value;
firebase.database().ref('books/' + bookName + '/bookInfo').update({
bookTitle : bookName
});