Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why Is Firebase modular version 9 not generating unique id for its documents in Real time Database as Firestore does?

I am working on firebase real-time database v9 but when I send data to the database the generated unique id for each document is not generated as it was in version 8 instead it maps the data in the name of collection hence I cant push another data. I have provided an image to show what is happening
enter image description here

    function writeUserData(e) {
    e.preventDefault();
    

    set(ref(realtime, "customers/"), {Name:cname,Contact: 
                contact,
                   Serial:serial,  Device: device, Served: 
               served, AmountC:amountc, 
                AmountP:amountp, Status:status }).then(() => {

                   toast.success("Data Saved Succefully");
      })
      .catch((err) => {
             setError(err.message);
      });
      
  }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The set() method does not generate a random ID. It just adds the data at the path specified. You must use push() to generate a random ID:

push(ref(realtime, "customers/"), {...data}).then(() => {
  console.log("Data added")
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading