【问题标题】:Cloud Firestore triggers " Your trigger must always point to a document"Cloud Firestore 触发器“您的触发器必须始终指向文档”
【发布时间】:2021-08-23 11:32:58
【问题描述】:

我想做的是……我的文档流程

batch(collection) -> {batchName}(document) -> subject -> {subjectName} -> 出勤

我想在考勤对象有更新时触发firestore功能

因此,在 Cloud Firestore 触发器的文档中,我找到了“您的触发器必须始终指向文档”这一行并附有示例...这是指向 documentation 的链接

这让我希望可以做到这一点,但我未能实现这一目标,

exports.attendenceTrigger = functions.firestore.document('batche/{batchName}/subjects/{subjectName}/attendance')

有可能吗?如果是,那我做错了什么?

【问题讨论】:

    标签: firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    你已经指定了一个集合的路径

    'batche/{batchName}/subjects/{subjectName}/attendance'
     (col)    (doc)      (col)      (doc)       (col)
    

    但是,您的路径必须指向文档,因此有效路径包括:

    // Triggers a function when a doc in subjects sub-collection is changed
    'batche/{batchName}/subjects/{subjectName}'
    
    // or
    
    // Triggers a function when a doc in attendance sub-collection is changed
    'batche/{batchName}/subjects/{subjectName}/attendance/{attendanceId}'
    

    attendance 是子集合吗?如果是,则使用上面的第二条路径在创建/修改/删除该集合中的文档时触发函数。如果attendance{subjectName} 文档中的一个字段,那么您应该使用第一行并从快照snapshot.data().attendance 访问attendance 字段。

    【讨论】:

    • 是的,出勤有一个对象列表,即:{attendenceId:{present: [],缺席: []},attendenceId:{present: [],缺席: []},attendenceId:{存在:[],缺席:[]}}.. 我在那个 id 上放了一个触发器,但它似乎没有工作
    • @NaveenSharma 您可以分享您的 Firestore 文档的屏幕截图吗?还有db的结构。
    • link ...这是您问的图像,是的,我知道出勤拼写错误
    猜你喜欢
    • 1970-01-01
    • 2020-02-18
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    • 2020-10-13
    相关资源
    最近更新 更多