firebase - 是否可以使用 Cloud Functions 在 Firestore 中获取 userID 或 currentUser 子集合?
问题描述
我需要帮助才能使用 Cloud Functions(Admin SDK)在 Firestore 的子集合中获取 userId。我试着得到 ' ...must be a non-empty string 或 non-empty array。'
假设分贝是const db = admin.firestore();
const snapshot = await db
.collection('clients')
.doc() // <-- If put a manually userId string, it works.
.collection('tokens')
.get();
const tokens = snapshot.docs.map(token => token.id);
编辑...
此函数从用户设备返回一个令牌。在.doc()中,如果我手动输入用户 ID,我可以获得记录在用户集合中的令牌。
.doc('oM5f5BcwJmA43EuuuElLAUUe7q12') // Example entering uid manually
部分代码:
export const sendToDevice = functions.firestore
.document('/clients/{clientId}/{warnings}/{warningId}')
.onCreate(async snapshot => {
const warning = snapshot.data();
const snapshot = await db
.collection('clients')
.doc() // <-- This can't be left blank,
.collection('tokens') // otherwise this function
.get(); // generates a new documentID.
const tokens = snapshot.docs.map(token => token.id);
...
数据库结构:
问候, 比尼奥
解决方案
推荐阅读
- ms-access - 当有人在 MS Access 中更改表中的记录时,我们能否获得“修改者”名称
- java - 每当我从主类调用任何方法时,我都会得到“0”值。这是为什么呢?
- swagger - OpenApi Codegen“获取架构名称失败:”
- node.js - nodejs put方法更新数据
- c# - 在运行时决定调用哪个类
- android - URI 链接未通过意图在浏览器上打开
- javascript - 下载属性允许 .html 在 chrome 中但在 Firefox 中不允许
- rest - 用于(反)序列化 REST API 的请求和响应的模型的命名约定
- python - Pandas 数据框的 Web 抓取
- azure - 无法使用 terraform/programmatic 将 Azure 密钥保管库与数据块集成