【发布时间】:2021-03-24 12:17:26
【问题描述】:
我已将此功能设置为等待新文档onCreate 事件。
我已检查我的文档字段是否正确:
这是我的收藏/文档的结构:users/{userID}/...
{
appVersion: [String]
displayName: [String]
email: [String]
isUserBlocked: [bool]
lastOnline: [timeStamp]
photoUrl: [String]
uid: [String]
...
}
Function for detecting new documents
// detects new users added
exports.newUserCreated = functions.firestore
.document("users/{userID}")
.onCreate(async (snap) => {
// New document Created
const user = snap.data();
console.log(user.displayName); // logs 'undefined'
console.log(user.uid); // logs 'undefined
return;
});
【问题讨论】:
-
如果您正在记录内容,您还应该显示这些代码行以及它们生成的特定输出。 “似乎没有显示任何字段”不是很具体 - 在查询中显示日志的具体输出。
-
另外,你没有注意sentToDevice返回的promise,这样会导致其他消息无法发送的问题。该函数应返回一个仅在所有异步工作完全完成后才解析的承诺。
-
edit:显示带有来自 Object.keys 循环日志的日志行的图片。还将添加 then 和 catchs 到 sentToDevice。但我确信这与有效载荷错误无关。
-
哪一行是每行日志代码的结果?请清楚这些记录代码行在您的函数中的位置,以及输出如何与这些行匹配。如果您有错误,您应该展开它们以更详细地显示。我建议将此代码缩减到不能按您期望的方式工作的最低限度,以便您可以更好地隔离问题。看起来您为了调试而处理了太多额外的东西。我强烈建议阅读:stackoverflow.com/help/minimal-reproducible-example
-
@DougStevenson 完成。
标签: node.js google-cloud-firestore google-cloud-functions firebase-cloud-messaging