将Cloud Functions与Firebase实时数据库一起使用时,您可以使用云功能定位特定字段.例如,给定这个JSON结构,我可以定位user1的电子邮件字段是否通过('/user/{userId}/email').onUpdate云功能更改.
{
"user": {
"user1": {
"name": "John Doe",
"phone": "555-5555",
"email": "john@gmail.com"
}
}
}
现在使用Firestore,我似乎无法定位特定字段,只能定位文档.如果是这种情况,定位电子邮件字段的Firestore云功能必须如下所示 ('/user/{userId}').onUpdate,并且每次user集合中的任何文档发生更改时都会触发.这将导致大量浪费的云功能触发.这就是Firestore的工作方式吗?它有一个优雅的工作吗?
database database-design firebase google-cloud-functions google-cloud-firestore
我是Typescript的新手,我正在尝试使用async和await功能.我每隔一段时间就得到一些fcm网络超时,我相信这与正确回复我的承诺有关.
这是我发送推送通知的云功能.使用await关键字的两个函数是incrementBadgeCount,和sendPushNotification:
export const pushNotification = functions.firestore
.document('company/{companyId}/message/{messageId}/chat/{chatId}')
.onCreate(async event => {
const message = event.data.data();
const recipients = event.data.data().read;
const messageId = event.params.messageId;
const ids = [];
for (const key of Object.keys(recipients)) {
const val = recipients[key];
if (val === false) {
ids.push(key);
}
}
return await Promise.all(ids.map(async (id) => {
const memberPayload = await incrementBadgeCount(id);
const memberBadgeNumberString =
memberPayload.getBadgeCount().toString();
const senderName = message.sender.name;
const senderId = message.sender.id;
const senderMemberName = message.senderMember.name;
const toId = …Run Code Online (Sandbox Code Playgroud) async-await typescript google-cloud-functions firebase-cloud-messaging