Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!