Firestore - 聆听特定的字段变化? [英] Firestore - Listen to specific field change?

查看:22
本文介绍了Firestore - 聆听特定的字段变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 firestore js sdk 监听特定字段的变化?

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

在文档中,他们似乎只展示了如何监听整个文档,如果任何SF"字段发生变化,都会触发回调.

In the documentation, they only seem to show how to listen for the whole document, if any of the "SF" field changes, it will trigger the callback.

db.collection("cities").doc("SF")
.onSnapshot(function(doc) {
    console.log("Current data: ", doc && doc.data());
});

推荐答案

你不能.Firestore 中的所有操作都针对一个完整的文档.

You can't. All operations in Firestore are on an entire document.

这也适用于 Cloud Functions Firestore 触发器(您只能接收以某种方式更改的整个文档).

This is also true for Cloud Functions Firestore triggers (you can only receive an entire document that's changed in some way).

如果您需要缩小某些数据的范围以从文档中检索,请将其放在子集合内的文档中,然后单独查询该文档.

If you need to narrow the scope of some data to retrieve from a document, place that in a document within a subcollection, and query for that document individually.

这篇关于Firestore - 聆听特定的字段变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆