Update without Where

Asked

Viewed 161 times

3

How to make an increment only on Child period of all students enrolled in Firebase?

Ex.: in SQL, I would use:

UPDATE alunos
SET periodo = periodo + 1 

Updating all students to their later period. How can I do in Firebase?

  • James, edit your question and your issue, which was the solution, add as an answer to this question.

  • 1

    @Ismael ready. Thanks for the suggestion! I’m new as a stack user.

  • 1

    @Henrique ready. Thanks for the suggestion! I’m new to the stack.

1 answer

2


I was able to accomplish what I needed by adapting the code below

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference usersRef = rootRef.child("users");
ValueEventListener eventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        String true = "true";
        for(DataSnapshot ds : dataSnapshot.getChildren()) {
            ds.child("SubmitCheck").getRef().setValue(true);
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {}
};
usersRef.addListenerForSingleValueEvent(eventListener);

Source: https://stackoverflow.com/questions/45162528/how-to-set-value-to-all-childs-data-in-firebase-database

Browser other questions tagged

You are not signed in. Login or sign up in order to post.