为什么 ref.getCollections() 不被识别为函数?

IT技术 javascript node.js reactjs firebase
2021-05-18 17:57:12

我正在做一个将用户数据存储在 cloud firestore 上的网站。我使用它一次获取用户文档的所有子集合:

db.collection('users').doc(userID).getCollections().then( collections => {
  /*I get my collections and I enjoy it :D*/
})

问题是无法识别此功能。我在控制台上找到了这条消息:

TypeError: db.collection(...).doc(...).getCollections is not a function

我知道否则我可以获得所有子集,但由于配额有限,我想保存最大的读数。所有其他 firebase 函数都在我的项目中工作(如get()set())并且getCollections()在文档中。谢谢您帮忙 !

2个回答

Google 团队将方法名称从“getCollections”替换为“listCollections”。所以你应该再次更新这个方法名称。在此处参考https://googleapis.dev/nodejs/firestore/latest/DocumentReference.html#listCollections

它适用于以下工具版本:firebase-tools v7.2.1、firebase-admin v8.3.0、firebase-functions v3.2.0。

在您的示例 db.collection('users').doc(userID) 返回 DocumentReference 并且据我所知 DocumentReference 对象不支持 getCollections 方法

这是文档https://firebase.google.com/docs/reference/js/firebase.firestore.DocumentReference