【问题标题】:Can we listen specific key value changes in firestore angular我们可以在firestore angular中监听特定的键值变化吗
【发布时间】:2021-12-22 02:09:15
【问题描述】:
getUserEventSummaryE(userId) {

return docData(doc(this.firestore, `/user/${userId}/event_summary/current/`), {idField : 'playing_summary'}).
  pipe(distinctUntilChanged((prev, curr) => _.isEqual(prev, curr)));

}

getUserEventSummaryE 应该仅在 playing_summary 更改时返回文档,但当前它在 playing_summary 键值更改以外的情况下返回文档数据。

示例文档数据

{
id: 1,
playing_summary: 'playing',
userbalance: 222,
dob: '2021-05-02'
}

当我更改 playing_summary 以外的其他值时,当前更改触发。

【问题讨论】:

    标签: javascript angular firebase google-cloud-firestore angularfire


    【解决方案1】:

    你不能监听文档中的任何键值,但是你可以在 document.它仅在文档更新时触发。

    exports.dbEventsOnUpdate = functions.firestore
    .document('events/{eventId}').onUpdate(async (change,context) => {
       
                const eventID = context.params.eventId;
                const newValue = change.after.data();
                const previousValue = change.before.data();
                const titleIsUpdated = newValue.title !== previousValue.title;
        })
    

    您可以查看this链接了解更多详情。

    【讨论】:

    • 我无法在 firebase 函数中执行此操作,因为我必须触发不支持的 GOOGLE ANALYTICS 4 标签
    • 所以,如果你想对上面的getUserEventSummaryE 进行更改,你不能在键值对上进行。
    猜你喜欢
    • 2017-02-07
    • 1970-01-01
    • 2019-02-17
    • 2018-05-31
    • 2020-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多