简体   繁体   English

如何访问/删除 Firestore 中随机创建的文档 ID?

[英]How can i access/delete a randomly created document id in firestore?

Code for deleting something (not working with this.task.id or this.task)删除某些内容的代码(不适用于 this.task.id 或 this.task)

const docRef = firebase.firestore().collection('users').doc(firebase.auth().currentUser.uid)
docRef.collection('tasks').doc(this.task.id).delete()

It looks like you are not handling the promise with a then or async/await, like the docs indicate https://cloud.google.com/firestore/docs/manage-data/delete-data#node.js .看起来您没有使用 then 或 async/await 处理promise ,就像文档指出https://cloud.google.com/firestore/docs/manage-data/delete-data#node.js

Also, your code implies the tasks are nested within the individual users document.此外,您的代码意味着任务嵌套在单个用户文档中。 If this is not the case, you might be referencing the wrong collection entirely.如果不是这种情况,您可能完全引用了错误的集合。 I suggest first doing a .get().then(res => console.log(res)) for both the user & their task.我建议首先为用户和他们的任务做一个.get().then(res => console.log(res)) If you can't get the document, you can't delete it.如果您无法获取该文档,则无法将其删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Angular 中创建新的 Firestore 文档时,如何访问自动创建的文档 ID? - How can I access the auto-created document ID when creating a new Firestore document in Angular? Firestore - 如何在我的 state 中添加文档 ID 及其数据? - Firestore - How can I add the Document ID and their data in my state? 我可以使用 Firestore 获取使用 batch().set 创建的文档的生成 ID 吗? - Can I get the generated ID for a document created with batch().set using Firestore? 如何在 Firestore 中的交易期间获取新创建文档的 ID? - How to get the ID of a newly created document during a Transaction in Firestore? ReactJS/Firestore:如何获取新建文档的 id - ReactJS/Firestore: how to get the id of a newly created document 如何在不指定文档 ID 和使用 Firestore 自动 ID 生成器的情况下添加到 Firestore? - How can I add to Firestore without specifying a document ID and utilising Firestores auto ID generator? 如何从预定功能访问 Firestore 中的文档 ID - How to access Document ID in Firestore from a scheduled function 如何使用安全规则限制一次仅在Firestore中删除一个文档? - How can i restrict to delete only one document at a time in firestore using security Rule? 如何从 mongoDb 文档中访问第二个 _id? - how can I access the second _id from the mongoDb document? 如何获取单击文档的 ID 并获取标题并在 Firestore 中使用/保存它? - How can I get the ID of the clicked document and get the title and use/save it in firestore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM