[英]Firestore: how can I get stream of updates from a server side?
tldr: I need to have Google Cloud Functions on my own backend. tldr:我需要在自己的后端安装Google Cloud Functions。
I write application, which uses firebase (especially firestore) as a transport layer between my own backend written on nodejs and client applications. 我编写了应用程序,该应用程序使用firebase(尤其是firestore)作为我自己在nodejs上编写的后端和客户端应用程序之间的传输层。
Sometimes, I need to catch some events from client on backend, but i want to avoid perform http queries directly to my backend (because I need to catch offline status, and other problems). 有时,我需要从后端的客户端捕获一些事件,但我想避免直接对后端执行http查询(因为我需要捕获离线状态和其他问题)。 It is better to made some changes in firestore documents, catch that changes on my backend and perform some business logic.
最好在Firestore文档中进行一些更改,在我的后端捕获这些更改并执行一些业务逻辑。
As for now, It can be solved with Cloud Functions, but this solution is not acceptable, because of delay between event and function invocation, and lack of invocation order. 到目前为止,它可以使用Cloud Functions解决,但是由于事件和函数调用之间的延迟以及缺少调用顺序,因此该解决方案尚不可接受。
Yet another solution, which is currently used in my project, is to making some changes to firestore document, and adding extra document, called "event" to other collection. 我的项目中当前使用的另一种解决方案是对Firestore文档进行一些更改,并向其他集合添加称为“事件”的额外文档。 On a server side, using firebase-admin sdk, I subscribe to that "events" collection and get realtime updates of it.
在服务器端,使用firebase-admin sdk订阅该“事件”集合并获取其实时更新。
This work great, but looks like overcomplicated. 这项工作很好,但看起来过于复杂。 Is there any way to subscribe from my backend to get all updates of all documents of firestore?
有什么办法可以从我的后端订阅以获得Firestore所有文档的所有更新? Ideal solution is to subscribe to updates, as it done in Cloud Functions: https://firebase.google.com/docs/functions/firestore-events?authuser=0
理想的解决方案是订阅更新,就像在Cloud Functions中一样: https : //firebase.google.com/docs/functions/firestore-events?authuser=0
The client and server SDKs don't have this capability. 客户端和服务器SDK不具备此功能。 Cloud Functions is really your only way to get notified of changes in Firestore that match a wildcard pattern.
云功能实际上是您获得Firestore中与通配符模式匹配的更改的通知的唯一方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.