jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
284 stars 64 forks source link

Using mongolite to connect to Change Streams? #213

Open doncqueurs opened 3 years ago

doncqueurs commented 3 years ago

I am wondering whether mongolite supports the continuous connection to a collection MongoDB Change Stream? If it does, how would I put set this up? Any code examples?

The use case I have in mind is to create a shiny application that is updating when any changes to the collection in the MongoDB are happening.

Reference: MongoDB Change Stream - https://docs.mongodb.com/manual/changeStreams/

jeroen commented 3 years ago

It isn't supported yet, but it is available in the c driver, so we could look into it: http://mongoc.org/libmongoc/current/mongoc_change_stream_t.html

doncqueurs commented 3 years ago

Thanks for taking a peak at the issue. The use case behind looking for this functionality is to update a Shiny application in real-time when changes in the DB are happening. The thought behind this is to facilitate real-time multi-user collaboration between users in Shiny Apps.

This is a bit the idea I have in mind building Shiny Apps on the basis of streaming data. In this case a (mock-up) example using sparklyr:

sc <- spark_connect()

server <- function(){
   iris <- sparklyr::reactiveSpark(
        sparklyr::stream_read_csv(cs, ...)
   )
   output$table1 <- renderDT(iris())
}

The whole setup with setting up a Spark environment to accomplish this seems to be a bit cumbersome so wondering what could be done with mongolite.