【问题标题】:Firestore Realtime Listener equivalent of "Child_Added"Firestore 实时侦听器相当于“Child_Added”
【发布时间】:2018-08-08 23:59:28
【问题描述】:

我正在尝试为 Firestore 实时侦听器找出解决方案。我知道您可以收听更改并在 onSnapshot 中查看添加、删除、更改的内容。但是有没有办法只收听添加内容?

我不喜欢每当数据发生变化或添加新文档时,查询都会检索每条数据。感觉就像是不必要的数据传输。尤其是如果您在3G网络

这是一个合理的担忧吗?还是查询返回的数据可以忽略不计?我只是想获得收藏的“新”添加

【问题讨论】:

    标签: firebase google-cloud-firestore


    【解决方案1】:

    你试过了吗?

    exports.createUser = functions.firestore
    .document('users/{userId}')
    .onCreate((snap, context) => {
      // Get an object representing the document
      // e.g. {'name': 'Marie', 'age': 66}
      const newValue = snap.data();
    
      // access a particular field as you would any JS property
      const name = newValue.name;
    
      // perform desired operations ...
    });
    

    【讨论】:

    • 他不是在谈论收听文档,而是要收听特定集合的新添加子项。
    猜你喜欢
    • 2012-07-03
    • 2020-11-11
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多