简体   繁体   English

Firestore:如何从服务器端获取更新流?

[英]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.

相关问题 从客户端获取Firestore服务器时间戳 - Get Firestore Server Timestamp from the client side 如何从FireStore获取收藏? - How can I get a collection from FireStore? 如何从 Firestore 服务器获取时间戳,而无需担心设备时钟与 Firestore 不同步的情况 - How can I get Timestamp from Firestore server without bothering for the case when device clock is out of sync with Firestore 如何从Firebase Firestore获取带有change.type ==“ added'的实时文档更新 - How do I get Realtime document updates from Firebase Firestore with change.type =="added' 如何将Tasks与Firestore onSnapshotListener结合使用以链接实时更新? - How can I use Tasks with Firestore onSnapshotListener to chain live updates? 如何通过 React 中的实时更新从 Firestore 文档参考中获取数据 - How to get data from Firestore Document Reference with realtime updates in React 如何确定 Firestore 快照是否来自服务器? - How can I determine if a Firestore snapshot is from the server? 如何从服务器端 Dart 应用程序执行 Firestore 管理任务? - How do I perform Firestore admin tasks from a server-side Dart application? 如何在客户端限制 Firestore 的 stream? - How to throttle Firestore's stream on client side? 如何从 firestore 查询快照中获取特定的文档数据? - How can I get specific document data from firestore querysnapshot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM