'flutter update all entries that have a specific item - firebase-database
How do I update many database entries at the same time that have a specific entry
In this case, all "posts" with the entry "8th St" at "street" should be updated, the item "checked" should be set to "true".
db structure:
+ posts
+ MPgslk7gshfasdjg
userName: Luke
street: 8th St
checked: false
...
+ sfdsflk7ghfdgrwj
userName: Joda
street: 1th St
checked: false
...
+ herjztwefhgrdhhr
userName: Vader
street: 8th St
checked: false
...
Something like:
final FirebaseDatabase _database = FirebaseDatabase.instance;
_database.ref().child("posts").orderByChild("street").equalTo("8th St").update({"checked": true});
thanks
Solution 1:[1]
Try this:
final _database = FirebaseDatabase.instance.reference();
await _database.child("posts").get().then(
(value) {
final data = Map<String, dynamic>.from(value.value);
data.forEach((key, value) {
if(value['street'] == "8th St"){
_database.child("posts/$key").update({"checked" : true});
}
});
}
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Saitoh Akira |
