I am unable to get GitHub - jchoi2x/cf-mongodb-polyfills: Allows using of mongodb npm package in cloudflare workers environment by polyfilling missing modules working with Atlas. I wonder if it’s because of the IPv6 address access problems between cloudflare & Atlas. Not sure how to fix that. Opened an issue here: BSONOffsetError error when trying to load from Atlas · Issue #4 · jchoi2x/cf-mongodb-polyfills · GitHub
you dont need that anymore.
Awesome, is this/can this be an official release that workers now support Mongodb drivers? The community solve the data api deprecation!
It is very exciting that Cloudflare is making progress on this. I haven’t had a chance to test these changes yet, but given this is just adding support for node:net, to connect to Atlas they’ll likely still need to implement node:tls.
Hello Ben,
I am also getting the same error BSONOffsetError but I am only getting it intermittently. I am certain that it is not related to the polyfill. As far as I can tell, it is likely due to a memory limit, or some other limit. I’m getting the error on M0 free cluster, when doing $vectorSearch. I can prevent it from occurring by setting a low limit, eg: 1 or 2 docs, as opposed to 10 or more. I don’t see any errors in my MongoAtlas dashboard, nor do any appear in Cloudflare.
If I run my app in locally in dev mode (not using wrangler) I don’t get the error, but with Wrangler, in preview or deployed, I do get the errors. So not really sure what is causing the issue, but it is frustrating.
I should probably file an issue, but I’m not sure where, any suggestion?
Just wanted to close the loop with an update blog post: Cloudflare Workers and MongoDB | ALEX BEVILACQUA
The latest release of Cloudflare Workers should support connectivity and interaction with MongoDB Atlas. I haven’t done a full barrage of testing, but I can confirm the limited tests I ran are successful ![]()
Thank for the test. Unfortunately i’m still getting a
“MongoServerSelectionError: socket.once is not a function”
because @alexbevi is, according to his own blog post, fully responsible for this fix release, you should hold him accountable for any issues ![]()
pretty sure that’s not what I’m implying (though I might have made the most noise) … but based on the error it does’t seem the workerd was updated to pull in the latest dependencies.
Maybe, though i followed your nice blog post
wrangler.toml
compatibility_flags = [“nodejs_compat_v2”]
compatibility_date = “2025-03-20”
pages_build_output_dir = “.svelte-kit/cloudflare”
I will have a look again i might have missed something (for now i’m staying on Vercel)
same here! I’m still getting a “MongoServerSelectionError: socket.once is not a function” in sveltekit project
is there an update on BSONOffsetError, it seems that cloudflare workers has a limit of 4075 bytes and anything bigger than that causes it to throw this BSONOffsetError