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

116
Visualizações
Firebase realtimeDB not creating new object, but replacing the old object's content

I wanted to store each input i submit, so i used firebase realtimeDB i modified the event of submiting with the code under, but each time its not creating a new file but replacing the old one's content Any solutions?? thanks

const db = getDatabase();
let d = new Date();
form.addEventListener("submit", (event) => {
  event.preventDefault();
  let inp = document.getElementById("inp").value;

  set(ref(db, "newSec/" + d.getTime()), { message: inp });

});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're creating the d value once, no matter how often the form is submitted. To get a new date for each time the form is submitted:

const db = getDatabase();
form.addEventListener("submit", (event) => {
  event.preventDefault();
  const d = new Date(); // 👈
  const inp = document.getElementById("inp").value;

  set(ref(db, "newSec/" + d.getTime()), { message: inp });
});

Or shorter:

const db = getDatabase();
form.addEventListener("submit", (event) => {
  event.preventDefault();
  const inp = document.getElementById("inp").value;

  set(ref(db, "newSec/" + Date.now()), { message: inp });
                       // 👆
});

On Firebase I'd recommend using its built-in push operation though, which does chronological ordering - but also works reliably even when you have many users doing this at the same time:

const db = getDatabase();
form.addEventListener("submit", (event) => {
  event.preventDefault();
  const inp = document.getElementById("inp").value;

  push(ref(db, "newSec"), { message: inp });
 // 👆
});
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