【问题标题】:Sync Firestore with Realtime database [closed]将 Firestore 与实时数据库同步 [关闭]
【发布时间】:2021-05-19 03:46:56
【问题描述】:

我的 Flutter 应用程序已与 Firestore 连接。

但是当涉及到与我的应用程序一起使用的 IOT 组件时,我必须使用实时数据库。如何使用实时数据库自动更新 Firestore 数据

例子


实时
车辆 -> ABC123 -> 纬度:3.256


Firestore
车辆 -> ABC123 -> 纬度:3.256

在特定时间段内自动同步数据库

【问题讨论】:

  • 根据iot 标签请勿使用。请用适当的标签澄清您的问题,因为IOT component 非常模糊。

标签: firebase firebase-realtime-database google-cloud-firestore components iot


【解决方案1】:

您只需要创建一个云函数来监视实时数据库中的更改并将这些更改写入 Firestore。

类似这样的东西(未经测试,但应该可以帮助您入门):

exports.syncFirestore = functions.database.ref().onWrite((change, context) => {
  const db = admin.firestore();

  db.document(change.after.key).set(change.after.val());
});

【讨论】:

  • 作为 Firestore 规则?
  • 答案中提到的云功能。
  • 你能解释一下云功能吗
  • @coder 您可以找到有关如何使用 Cloud Functions 的信息here
  • @RafaelLemos 好的,谢谢,我会调查的。自从我将其开发为学术原型后,它是付费版本吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-28
  • 1970-01-01
  • 1970-01-01
  • 2018-01-17
  • 1970-01-01
  • 2020-02-16
  • 2019-08-07
相关资源
最近更新 更多