Reputation: 33
I want to Update the All Students of class where classection=Six:B Which Query I can use please Guide there Are many students I want to update All the student of six class at the same time.
Upvotes: 0
Views: 43
Reputation: 138824
I want to Update the All Students of class where classection=Six:B
To achieve that, you need to use a Query to filter the students based on the "classection" property. To also perform an update, for example, to change the value from "Six:B" to "Six:C", please see use the following lines of code:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference studentsRef = rootRef.child("Students");
Query classSectionQuery = studentsRef.orderByChild("classection").equalTo("Six:B");
classSectionQuery.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@Override
public void onComplete(@NonNull Task<DataSnapshot> task) {
if (task.isSuccessful()) {
for (DataSnapshot ds : task.getResult().getChildren()) {
ds.child("classection").getRef().setValue("Six:C");
}
} else {
Log.d(TAG, task.getException().getMessage()); //Don't ignore potential errors!
}
}
});
The result of this code will be the update of all students "WHERE" classection is equal to "Six:B".
Upvotes: 1