Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
How to implement atomicity in firebase realtime database. For my problem

For the given code, I try to implement atomicity. In this, if the first push gets executed then execute the second push if it fails then roll back the first push and start again from the top. If the first push is executed successfully then execute the second if it is executed successfully then execute the third and if the third failed then roll back both the first and second push. and start execution again from the top. if it passes then save the data to the real-time database.

               "if(message){
                    ref.push({
                        mobNo : senderMobNo,
                        message : message,
                        time : d
                    });
                    ref2.push({
                        mobNo : senderMobNo,
                        message : message,
                        time : d
                    });
                    ref3.push({
                        mobNo : senderMobNo,
                        message : message,
                        time : d
                    });
                }"
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If the recursion doesn't work for you, and you want all data to be committed, then you should consider performing simultaneous additions to multiple locations in the JSON tree with a single call to update().

In this way, you can write the new messages simultaneously to the desired locations. These operations are atomic, either all updates succeed or all updates fail. In this case, there is no need to roll something back.

about 4 years ago · Juan Pablo Isaza Relatório

0

It sounds like you want to perform a multi-path update, which is a way to combine multiple updates in a single API call:

if(message){
    const updates = {};
    let id = ref.push().key; // generate a push key
    updates[key] = {
        mobNo : senderMobNo,
        message : message,
        time : d
    });
    id = ref.push().key; // generate another push key
    updates[id] = {
        mobNo : senderMobNo,
        message : message,
        time : d
    });
    id = ref.push().key; // generate a third push key
    updates[id] = {
        mobNo : senderMobNo,
        message : message,
        time : d
    });
    ref.update(updates); // send them all to the database in one go
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda