如何在 firestore 中为特定文档编写函数?
how to write function for a specific document in firestore?
下面是我在youtube上用过的功能。
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.androidPushNotification =
functions.firestore.document('MyMoneyNotifications/{MyPercentageMoney}').onCreate(
(snapshot, context)=>
{
admin.messaging().sendToTopic(
"new_user_forums",
{
notification:{
title:snapshot.data().title,
body: snapshot.data().body
}
});});
它工作正常。
但我想检查以下结构。
Notifications(collection)
->UserId(document)
->MyNotification(collection)
->notify1
->notify2
现在,我想检查特定用户是否有任何新通知。如何在 firebase 函数中检查集合“MyNotification”
如果您想收听子集,则可以将路径设置为:
exports.androidPushNotification =
functions.firestore.document('Notifications/{userId}/MyNotification/{notificationId}')
您可以在 documentation
中阅读更多相关信息
下面是我在youtube上用过的功能。
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.androidPushNotification =
functions.firestore.document('MyMoneyNotifications/{MyPercentageMoney}').onCreate(
(snapshot, context)=>
{
admin.messaging().sendToTopic(
"new_user_forums",
{
notification:{
title:snapshot.data().title,
body: snapshot.data().body
}
});});
它工作正常。 但我想检查以下结构。
Notifications(collection)
->UserId(document)
->MyNotification(collection)
->notify1
->notify2
现在,我想检查特定用户是否有任何新通知。如何在 firebase 函数中检查集合“MyNotification”
如果您想收听子集,则可以将路径设置为:
exports.androidPushNotification =
functions.firestore.document('Notifications/{userId}/MyNotification/{notificationId}')
您可以在 documentation
中阅读更多相关信息