Home > Back-end >  Why Is Firebase modular version 9 not generating unique id for its documents in Real time Database a
Why Is Firebase modular version 9 not generating unique id for its documents in Real time Database a

Time:01-04

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);
      });
      
  }

CodePudding user response:

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")
})
  • Related