Cloudflare Workers integration is now possible

Let’s hope for the best then.
Any workaround for this issue in the meantime?

Until Cloudflare adds native support for TLS to their workers the workaround is to leverage MongoDB’s Data API instead (see Create a REST API with Cloudflare Workers and MongoDB Atlas | MongoDB for an example of this)

1 Like

You can also do this using a service binding with an RPC worker. One would still use Realm, but instead of making calls to the database via REST/http requests one can call methods directly from main app. It is explained in this blog post from Cloudflare.
We've added JavaScript-native RPC to Cloudflare Workers.
I build a test app based on todo-list example in the REST-API, I could share the code if anyone is interested.

Hi MongoDB @BlindChicken, Please do share the code to connect to mongodb using cf workers.

I have been using the data api, and while it works with workers, the limitations such as the inability to perform simple queries such as findOneAndUpdate and the 2000 ms connection time is greatly limiting our decision to use Mongodb in future projects.

Even using serverless database option provided by cf, i belive the nodes are not distributed globally is that right?

Really looking to speed up Data API access or finding a driver that would work with cf workers. – your update would be appreciated.

Now that MongoDB has suddenly deprecated Realm Sync and the DataAPI this leaves us in the dust. What are the alternatives? We may be switching over to cloudflare D1 or using hyperdrive with postgres to solve our solution. MongoDB please update the driver to support cloudflare workers.

This workaround is no longer viable with the Data API deprecation. Hopefully someone at Mongo can put a little pressure on Cloudflare to add TLS worker support.

Some good news Cloudflare seems to have solved it for us, I am yet to test it, but looks like the native mongodb driver now works with workers.

@Rishi_uttam TL;DR - you still can’t use MongoDB’s Node.js driver from Cloudflare Workers even after their latest round of updates.

I’ve written this up in a bit more detail at Why Cloudflare Workers Don't Work With MongoDB | ALEX BEVILACQUA, but it seems like we’re still not quite there.

Excellant write up, and you also addressed previous MongoDB blog posts that are now invalidted due to the deprecation.

If would be amazing if you can report this to the issues channel on github as advised in the blog post here: Sign in to GitHub · GitHub

Hopefully someone would look at it and atleast remove mongodb from the post so as to not confuse the rest of us.

I am now going to look in to neurelo but another monthly fee just to get this all working seems very hacky right now. Last option is to try realm-web which I have used in production before, however its as slow as the old data api, but does allow me to bypass server side and write the connection script on the front end (with the added load of 200kb for real-web js) Wait has realm-web been deprecated too?! nothing is very clear at this point.

Thanks

There are some community solutions cropping up for the Data API (see discussion at Data API and HTTPS Endpoints are Deprecated? - #14 by Sven_Glockner).

I haven’t validated any of these personally, but there would definitely be options to explore that don’t require a subscription.

If would be amazing if you can report this to the issues channel on github as advised in the blog post here: Sign in to GitHub · GitHub

I’ve opened 🐛 BUG: `mongodb` can be imported but not successfully used with nodejs_compat_v2 · Issue #6684 · cloudflare/workers-sdk · GitHub to continue tracking this issue.