[英]Uncaught (in promise) FirebaseError: No document to update
I made a firestore database that looks like this.我制作了一个看起来像这样的 Firestore 数据库。
I'm trying to make "stocks : 999" value change, so that it can be 998, 997, etc...我正在尝试更改“股票:999”的值,以便它可以是 998、997 等...
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.因此,我遵循了有关 firebase 文档的说明( https://firebase.google.com/docs/firestore/manage-data/add-data#web-version-9_8 ),但是在尝试使其工作时遇到了错误.
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.在这里,重要的是const toUpdate = doc(db, "stocks", "stocks")
和const update = ()...
,其他都很好。
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.顺便说一句,我正在使用 React,我不知道这是否有用。
Your code is trying to update a document with the path "/stocks/stocks".您的代码正在尝试使用路径“/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).我倾向于同意,因为您在屏幕显示中显示的文档具有路径“/stocks/sL..G1”(已编辑)。 You will need to use the correct document ID to build a path to the document to update.您将需要使用正确的文档 ID 来构建要更新的文档的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.