Home > Net >  I want edit data in firebase database?
I want edit data in firebase database?

Time:11-14

I want to edit data in firebase database.

But on my syntax I don't get right answer. Can you help me.

 const addNewData = async (e) => {
  e.preventDefault();

  let data = {
  sifra:sifraRef.current.value,
  naziv:nazivRef.current.value,
  detalji_dijete:detaljiRef.current.value,
  opis:opisRef.current.value,
  broj_obroka:brojObrokaRef.current.value,
  napomena:napomenaRef.current.value
}  
const uuid = uid();
await updateDoc(collection(db, `namirnice/${uuid}`), data)


  close();

  } 

I changed my syntax but I get this answer in console. BTW all these ways are from youtube tutorials.

But my console.log right now is:Uncaught (in promise) FirebaseError: Invalid collection reference. Collection references must have an odd number of segments, but namirnice/5b61b327e2e has 2.

CodePudding user response:

Can you try updateDoc
Firestore updateDoc documentation
Example

FYI, if you dont know, collections and documents are different. Difference in references :

const alovelaceDocumentRef = doc(db, 'users', 'alovelace'); //even number of segments
const usersCollectionRef = collection(db, 'users'); //odd number of segments

Other differences discussed in Firestore data model documentation.

  • Related