Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda