如何保持Firebase与另一个数据库同步 [英] How to keep Firebase in sync with another database

查看:251
本文介绍了如何保持Firebase与另一个数据库同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要保持我们的 Firebase 数据与其他数据库同步文本搜索(在 ElasticSearch 中)和其他类型的查询 Firebase 支持。

We need to keep our Firebase data in sync with other databases for full-text search (in ElasticSearch) and other kinds of queries that Firebase doesn't easily support.

这需要尽可能接近实时,我们不能只导出 Firebase JSON 或任何类似的东西,除了这将是相当大的事实。

This needs to be as close to real-time as possible, we can't just export a nightly dump of the Firebase JSON or anything like that, aside from the fact that this will get rather large.

我最初的想法是运行 Node.js 客户端监听 child_changed child_added child_removed etc ...所有主要列表的事件,但是这可能会得到一点unweildy,如果客户端在一段时间后重新连接,它将是一个可靠的同步方式?

My initial thought was to run a Node.js client which listens to child_changed, child_added, child_removed etc... events of all the main lists, but this could get a bit unweildy and would it be a reliable way of syncing if the client re-connects after a period of time?

我的下一个想法是维护项目已更改事件的列表,并在每次创建/更新项目时写入,类似于 Firebase工作队列示例。队列可以包含已改变的数据的完整路径,而工作者只是消耗它,并相应地更新本地数据库。

My next thought was to maintain a list of "items changed" events and write to that every time an item is created/updated, similar to the Firebase work queue example. The queue could contain the full path to the data which has changed and the worker just consumes that and updates the local database accordingly.

这里的问题是每一位代码使更新必须记住写入此队列否则两个系统将失去同步。

The problem here is every bit of code which makes updates has to remember to write to this queue otherwise the two systems will get out of sync. Some proxy code shouldn't be too hard to write though.

有没有其他人做任何类似的任何成功?

Has anyone else done anything similar with any success?

推荐答案

对于搜索查询,您可以直接与ElasticSearch集成;没有必要与辅助数据库同步。 Firebase有整合的网志文章,以及lib,手电筒,以使此快速和无痛。

For search queries, you can integrate directly with ElasticSearch; there is no need to sync with a secondary database. Firebase has a blog post about integrating and a lib, Flashlight, to make this quick and painless.

这篇关于如何保持Firebase与另一个数据库同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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