我想从 Firebase 子集合中删除文档。我尝试通过以下方式做到这一点:
firestore.collection('categories').doc(categoryId).collection('books').doc(bookId).delete();
但这不起作用。
但是,我可以从集合中删除文档:
firestore.collection('categories').doc(categoryId).delete();
我是不是忽视了什么?应该如何运作?
UPDATED:
const firebase = require('../firebase/firebaseAdmin');
const firestore = firebase.firestore();
module.exports = {
removeBookFromCategory: (categoryId, bookId) => (
firestore
.collection('categories')
.doc(categoryId)
.collection('books')
.doc(bookId)
.delete()
),
};
我在这里有正确的 ID,但收到 500 错误:
错误:参数“documentPath”不是有效的资源路径。路径必须
是一个非空字符串。
当您删除具有关联子集合的文档时,子集合不会被删除。它们仍然可以通过引用访问。
当你执行时,
firestore.collection('categories').doc(categoryId).collection('books').doc(bookId).delete();
它将删除该文档。但它不会删除子集合。如果您想删除子集合,则必须手动完成。
请参考here https://firebase.google.com/docs/firestore/manage-data/delete-data#collections
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)