Firestore - Listen to specific field change?

前端 未结 4 1917
星月不相逢
星月不相逢 2020-11-29 09:43

How can I listen to a specific field change with firestore js sdk ?

In the documentation, they only seem to show how to listen for the whole document, if any of the

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 10:43

    Just out of the box what I do is watching before and after with the before and after method

    const clientDataBefore = change.before.data();
    console.log("Info database before ", clientDataBefore);
    
    const clientDataAfter = change.after.data();
    console.log("Info database after ", clientDataAfter );
    

    For example now you should compare the changes for a specific field and do some actions or just return it.

    Some more about before.data() and after.data() here

提交回复
热议问题