Mongodb connect err
I want to connect to the community version of mongodb, but the error shown in the picture appears. What should I do? Can anyone help? Thank you!
3 Replies
you can't use mongodb lib on worker. worker don't have "fs"package from node .It don't have filesystem and tcp connect to mongo db .
if you want to use mongo you should checking mongodb atlas api. it use http request
i think @windwp is refering to the DataAPI which indeed uses normal fetch requests, the downsides is that there is latency here on the atlas side, i do remember reading somewhere more database npm packages are soon to be supported?
to my knowledge, in general, serverless is a bit tricky to connect DB systems, especially MongoDB. Serverless is ephemeral, short-lived, so which would create many connections, causes high load on DB systems. Postgres has a work-around though.
https://blog.cloudflare.com/workers-tcp-socket-api-connect-databases/
The Cloudflare Blog
Announcing connect() — a new API for creating TCP sockets from Clou...
Today, we are excited to announce a new API in Cloudflare Workers for creating outbound TCP sockets, making it possible to connect directly to databases and any TCP-based service from Workers