使用node.js从Firestore中的子集合中删除文档

dig*_*fee 5 node.js firebase google-cloud-firestore

我想从Firebase子集合中删除一个文档。我正在尝试通过以下方式做到这一点:

firestore.collection('categories').doc(categoryId).collection('books').doc(bookId).delete();
Run Code Online (Sandbox Code Playgroud)

而且它不起作用。

但是,我可以从集合中删除文档:

firestore.collection('categories').doc(categoryId).delete();
Run Code Online (Sandbox Code Playgroud)

我会看不见东西吗?应该如何运作?

更新:

const firebase = require('../firebase/firebaseAdmin');
const firestore = firebase.firestore();

module.exports = {
  removeBookFromCategory: (categoryId, bookId) => (
    firestore
      .collection('categories')
      .doc(categoryId)
      .collection('books')
      .doc(bookId)
      .delete()
  ),
};
Run Code Online (Sandbox Code Playgroud)

我在这里有正确的ID,但出现500错误:

错误:参数“ documentPath”不是有效的ResourcePath。路径必须是非空字符串。

Sam*_*ath 7

当您删除具有关联子集合的文档时,子集合不会被删除。它们仍然可以通过引用访问。执行时,

firestore.collection('categories').doc(categoryId).collection('books').doc(bookId).delete();
Run Code Online (Sandbox Code Playgroud)

它将删除该文档。但它不会删除子集合。如果要删除子集合,则必须手动完成。请参考这里