So i have this query and currently collects all the data with materialName
equals to gold. I wanted change all to false.
// materialName = \"gold\"
You need to loop over the results (since there can be multiple matching nodes) and then update each:
database.ref('/app/posts')
.orderByChild('material')
.equalTo(materialName)
.once('value', function (snapshot) {
snapshot.forEach(function(child) {
child.ref.update({material: false});
});
});
You'll also note that I changed your .startAt().endAt()
to an equalTo()
, which gives the same results with less code.