DEV Community

RaFi
RaFi

Posted on • Edited on

Unhandled Rejection (FirebaseError): No document to update

When i creating my twitter clone with nextjs i got this error and it takes my 10 hours ,but luckily i got solution in my mind
my code was

const imageRef = ref(storage, `posts/${docRef.id}/image`);
 //setselctedfile is an error
 if(selectedFile){
  await uploadString(imageRef, selectedFile ,"data_url").then(async()=>{
    const downloadURL = await getDownloadURL(imageRef);
  await updateDoc(doc(db, "posts", docRef.id),{
    image:downloadURL
  }

  );
  });
 }
Enter fullscreen mode Exit fullscreen mode

then i change updateDoc to onSnapshot

const imageRef = ref(storage, `posts/${docRef.id}/image`);
 //setselctedfile is an error
 if(selectedFile){
  await uploadString(imageRef, selectedFile ,"data_url").then(async()=>{
    const downloadURL = await getDownloadURL(imageRef);
  await onSnapshot(doc(db, "posts", docRef.id),{
    image:downloadURL
  }

  );
  });
 }
Enter fullscreen mode Exit fullscreen mode

that's work for me .

Top comments (0)