【发布时间】:2021-06-24 18:19:39
【问题描述】:
我是新人,如果需要更多信息,请告诉我!
我正在尝试将 MessageBird 与 Firestore 集成。除了接受电话号码的“to”字段外,它可以将所有内容写入数据库。我正在记录该号码,并且它在控制台中正确输出,除了在我的 Firestore 中它被存储为undefined。如果有人能提供任何关于为什么会这样的见解,那将不胜感激。我被困了一段时间。 (附上出现问题的部分功能和控制台截图)
我最初尝试在doc.data()?.phoneNum 行上不使用await 并刚刚收到[object Promise]。现在它正在控制台中打印,我知道这与它无关。请帮忙!
admin.auth().listUsers().then((res) => {
res.users.forEach((userRecord) => {
try {
const dbRef = firestore()
.collection("collection").doc(userRecord.uid)
.collection("collection").doc(document);
dbRef.get().then((context) => {
if (context.exists) {
firestore()
.collection("collection")
.doc(userRecord.uid).get()
.then(async (doc) => {
number = await doc.data()?.field1;
console.log("Sending message to: " + number);
});
firestore().collection("collection")
.doc()
.create({
channelId: "id",
type: "text",
content: {
text: "message",
},
to: `${number}`,
});
functions.logger.log("SUCCESSFULLY SENT TO DB");
} else {
// console.log("**Unviable user**");
}
});
} catch (error) {
console.log(error);
}
});
});
【问题讨论】:
标签: typescript firebase google-cloud-firestore messagebird