简体   繁体   English

未捕获(承诺)FirebaseError:没有要更新的文档

[英]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.

相关问题 未捕获(承诺)FirebaseError:没有要更新的文档。 如果我对文档 ID 进行硬编码,则只能更新文档 - Uncaught (in promise) FirebaseError: No document to update. Can only update document if I hard code the document id 未捕获(承诺):FirebaseError - Uncaught (in promise): FirebaseError Firestore 更新数据未捕获(承诺)FirebaseError:缺少或权限不足 - Firestore update data Uncaught (in promise) FirebaseError: Missing or insufficient permissions 未捕获(承诺)FirebaseError:缺少权限或权限不足 - Uncaught (in promise) FirebaseError: Missing or insufficient permissions “ Uncaught (in promise) FirebaseError: Invalid document reference。文档引用必须有偶数个段,但用户有 1 个。” 反应 - " Uncaught (in promise) FirebaseError: Invalid document reference. Document references must have an even number of segments,but Users has 1." Reactjs updateDoc:未捕获的 FirebaseError:无效的文档引用 - updateDoc: Uncaught FirebaseError: Invalid document reference Uncaught (in promise) FirebaseError: 调用者在 firestore 中没有权限 - Uncaught (in promise) FirebaseError: The caller does not have permission in firestore 未捕获(承诺中)FirebaseError:注册客户端时缺少权限或权限不足 - Uncaught (in promise) FirebaseError: Missing or insufficient permissions when registering client 未捕获(承诺中) FirebaseError:缺少权限或权限不足。 在新 Rr - Uncaught (in promise) FirebaseError: Missing or insufficient permissions. at new Rr Uncaught (in promise) FirebaseError: Function collection() cannot be called with an empty path - Uncaught (in promise) FirebaseError: Function collection() cannot be called with an empty path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM