Update only 1 item within firebase’s

Asked

Viewed 880 times

2

I have the following knot in firebase:

inserir a descrição da imagem aqui

Inside this node I need to access the user value and change it, to do this I am using this code:

                   firebaseSenha = ConfiguracaoFirebase.getFirebase().child("usuarios").child(identificadorUsuarioLogado);

                firebaseSenha.addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        Usuario usuarioSenha = dataSnapshot.getValue(Usuario.class);

                        String senhaRecuperada = senha.getText().toString();

                        firebaseSenha = ConfiguracaoFirebase.getFirebase();
                        firebaseSenha = firebaseSenha.child("usuarios").child(identificadorUsuarioLogado);

                        Usuario usuario = new Usuario();

                        usuario.setSenha(senhaRecuperada);

                        firebaseSenha.setValue(usuario);
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });

However these code is causing all other fields within the node to be deleted and about only the password value changed, as I do to change only the password value, without deleting the others.

After executing the code it looks like this:

inserir a descrição da imagem aqui

  • You read in English? Here has an answer to your question.

  • 1

    It worked out! Thank you!

2 answers

0

You can update only the password attribute

Configuracaofirebase.getFirebase(). Child("users"). Child(identifierUsuarioLog). Child("password"). setValue("your password")

0

Whoa, that’s all right!?

there is no need for you to change everyone, you can just give a setValue() only in the attribute you want to change.

firebaseSenha = firebaseSenha.child("usuarios").child(identificadorUsuarioLogado);

//sua logica.... e agora vc poderá setar apenas a senha.

firebaseSenha.child("senha").setValue(senhaRecuperada);

Browser other questions tagged

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