简体   繁体   English

如何让chrome扩展监听mongodb文件变化?

[英]How to make a chrome extension listen to mongodb document changes?

I am building a link syncing chrome extension.我正在构建一个链接同步 chrome 扩展。 I managed to push the links to mongodb database using a custom made REST API. When a document changes in mongodb database, I am able to listen to those changes using change stream in the custom made REST API. However, I am unable to pass those changes to the chrome extension, when a document change occurs in the database.我设法使用自定义 REST API 将链接推送到 mongodb 数据库。当 mongodb 数据库中的文档发生更改时,我能够使用自定义 stream 中的更改 stream来收听这些更改,但是无法将这些更改传递给 8.14281316308 am当数据库中发生文档更改时,更改 chrome 扩展。

Is there any way, to make a chrome extension listen to changes in mongodb database and get those changes as soon as the change occurs?有没有办法让 chrome 扩展监听 mongodb 数据库中的变化,并在变化发生后立即获取这些变化?

It is possible to make a Chrome extension listen for changes in a MongoDB database, but this will require some additional work on your part.可以让 Chrome 扩展程序监听 MongoDB 数据库中的更改,但这需要您做一些额外的工作。 One way to do this would be to use the WebSocket API to create a persistent connection between your Chrome extension and your custom REST API. Your REST API can then use the MongoDB change stream to listen for changes in the database and pass those changes back to the Chrome extension over the WebSocket connection. One way to do this would be to use the WebSocket API to create a persistent connection between your Chrome extension and your custom REST API. Your REST API can then use the MongoDB change stream to listen for changes in the database and pass those changes back to通过 WebSocket 连接的 Chrome 扩展程序。 This way, the Chrome extension can receive real-time updates from the database as soon as changes occur.这样,Chrome 扩展程序可以在发生更改时立即从数据库接收实时更新。

Alternatively, you could use polling to periodically check for changes in the database and update the extension accordingly.或者,您可以使用轮询来定期检查数据库中的更改并相应地更新扩展。 This approach would not provide real-time updates, but it would be easier to implement and may be sufficient for your needs, depending on the specific requirements of your extension.这种方法不会提供实时更新,但它更容易实现,并且可能足以满足您的需求,具体取决于您的扩展的具体要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM