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

Uncaught (in promise) FirebaseError: No document to update

I made a firestore database that looks like this.

enter image description here

I’m trying to make "stocks : 999" value change, so that it can be 998, 997, etc…

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

So I followed given instructions on firebase documentation (https://firebase.google.com/docs/firestore/manage-data/add-data#web-version-9_8), but I bump into an error when trying to make it work.

const [stock, SetStock] = useState([]);
const toUpdate = doc(db, "stocks", "stocks");

  useEffect(
    () =>
      onSnapshot(collection(db, "stocks"),(snapshot) => 
      SetStock(snapshot.docs[0].data().stocks)
     ),
 [] 
 );
 
 const update = () => {
   updateDoc(toUpdate, {
    stocks : increment(-1)
  });
  
 }

In here, the important things are const toUpdate = doc(db, "stocks", "stocks") and const update = ()..., the other are working great.

Anyways, after clicking the button that triggers "update", I get an error that says
enter image description here

Why ?

By the way, I am using React, I don’t know if this might be useful.

>Solution :

Your code is trying to update a document with the path "/stocks/stocks". The error message is telling you that document doesn’t exist. I’m inclined to agree, since the document you show in the screenshow has the path "/stocks/sL..G1" (redacted). You will need to use the correct document ID to build a path to the document to update.

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