Firebase how to update child value in javasscript
2 problems:
1.You forgot to add "\eventos" on you child path.
2.dont use .set(), because it will delete all the other data.
Instead of .set() use .update().
Try this code:
firebase.database().ref('usuario')
.on('value',event =>{
event.forEach(user =>{
user.child('eventos').forEach(evento =>{
if (evento.val().categoryId === payload.id){
//Here is where i try to update the childe value, in my case category
let ref = firebase.database().ref('usuario/'+user.key+'/eventos/'+evento.key+'/'+evento.val().category)
.update(payload.name)
console.log(ref)
}
})
});
});
Let me know if it still dont work
Is it possible to update only specific data on my child on firebase?
Yes it is possible:
FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
String useruid=user.getUid();
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Accounts").child("user").child(useruid);
ref.child("date").setValue(newdate);
ref.child("email").setValue(newemail);
ref.child("name").setValue(newname);
ref.child("type").setValue(newtype);
If you have the list of names in a listview and you want to update them then, you can do the following:
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final String selectedFromList = (String) listview.getItemAtPosition(position);
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Accounts").child("user").child(useruid);
ref.orderByChild("name").equalTo(selectedFromList).addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//update values here
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
});
How to update value of a particular child node in firebase realtime database?
Please note that Firebase database does not accept null values, so if you try to update a node with anything that results in null value, the node will be deleted. For more information, please check the documentation on https://firebase.google.com/docs/database/admin/save-data
I'm not sure if that is the reason behind your issue, I would need more information on what updatedPrice is, but try to log this variable and examine its contents, maybe it is resolving as a null value and causing the error.
Good luck!
How to update particular value of child in Firebase DB
For Updating values at a particular node in Firebase Realtime Database, use:-
You can either use
runTransactionBlock:
func updateTotalNoOfPost(completionBlock : (() -> Void)){
let prntRef = FIRDatabase.database().reference().child("komal_kyz").child(your_AuroID).child("dealResul")
prntRef.runTransactionBlock({ (resul) -> FIRTransactionResult in
if let dealResul_Initial = resul.value as? Int{
//resul.value = dealResul_Initial + 1
//Or HowSoEver you want to update your dealResul.
return FIRTransactionResult.successWithValue(resul)
}else{
return FIRTransactionResult.successWithValue(resul)
}
}, andCompletionBlock: {(error,completion,snap) in
print(error?.localizedDescription)
print(completion)
print(snap)
if !completion {
print("Couldn't Update the node")
}else{
completionBlock()
}
})
}While calling this function:-
updateTotalNoOfPost{
print("Updated")
}Or just call
updateValues
let prntRef = FIRDatabase.database().reference().child("komal_kyz").child(your_AuroID)
prntRef.updateChildValues(["dealResul":dealResult])
PS:- Prefer using runTransactionBlock:
instead of .updateChildValues
if you only want to increment a particular node. Also read this: -https://stackoverflow.com/a/39458044/6297658
How can I change the value of child in Firebase database?
If you've got the DataSnapshot
for a path in the database, it's easy to get the DatabaseReference
that you need to update it:
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("BetSlip");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot ds: snapshot.getChildren()) {
String timestamp = ""+ ds.child("timeStamp").getValue();
String toggleStatus = ""+ ds.child("toggleStatus").getValue();
if (timeStamp.equals(timestamp) && toggleStatus.equals("on")) {
ds.child("toggleStatus").getRef().setValue("off");
}
if (timeStamp.equals(timestamp) && toggleStatus.equals("off")) {
ds.child("toggleStatus").getRef().setValue("on");
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
throw error.toException(); // never ignore errors
}
});
Since you're updating the node based on its existing value, strictly speaking you might need to use a transaction for it.
Related Topics
Ruby: Loaderror - Library Not Found for Class Digest::Sha1 -- Digest/Sha1
Swift Language Multicast Delegate
Invert Calayer Mask That Is Based on a Stroke (No Fill)
Uibezierpath Subclass Initializer
Routing Between Points with Mapbox
iOS Sharecontext Tapping on Suggestion Intent Property of Extensioncontext Is Nil
How to Call a View Controller Function from an iOS Appdelegate
Delete Image from Photo Gallery
Swift 3:Url Image Makes Uitableview Scroll Slow Issue
Pure Swiftui Login, Signup, Register Flow, Is It Possible
Nsexceptionallowsinsecurehttploads Not Working for Ip Addresses
Swift/iOS Refreshing App Data When in Background
Coredata Conditionally Fetching on Nsdate Using Nspredicate (Swift)
iOS Development App Startup Crash
How to Debug Swift Playgroundbook
Outline Uilabel Text in Uilabel Subclass
Target Is Not Found, Please Reconnect the Device, Xcode:Device Support File