Reputation:
I made a firestore database that looks like this.
I'm trying to make "stocks : 999" value change, so that it can be 998, 997, etc...
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
Why ?
By the way, I am using React, I don't know if this might be useful.
Upvotes: 2
Views: 1701
Reputation: 317322
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.
Upvotes: 0