I'm trying to set "pretend" value using the following code but it didn't work.
dataBase.ref().orderByChild('en_word').equalTo('pretend').set({
en_word: 'Pretend'
})
CodePudding user response:
Writing a value to the Firebase requires that you know the complete, exact path where you want to write. It doesn't support so-called update queries, where you send a query and a write operation to the database in one go. Instead you will have to:
- Execute the query.
- Loop over the results.
- Update each of them in turn.
So in your case that'd be something like:
let query = dataBase.ref().orderByChild('en_word').equalTo('pretend');
query.once("value").then((results) => {
results.forEach((snapshot) => {
snapshot.ref.update({
en_word: 'Pretend'
})
})
})