Is it possible to use MongoDB in a worker?

Hey, I want to use MongoDB as my db, but I read that the nodejs mongodb driver uses websockets to connect to mongodb which isn't viable in a worker, I read that it's possible to use Atlas mongodb Data/HTTP API but it seems that it is deprecated, is there a proper way to user mongodb in a worker? Thanks.
4 Replies
Masim
Masim5mo ago
Yes, it is possible to use you need to set up your own API layer that acts as a bridge between your MongoDB database and Workers.
pepechu
pepechuOP5mo ago
Yeah, but that API layer would have to be a regular node service or something similar and won't run on the edge, I meant is it possible to connect to mongo directly from the worker
Masim
Masim5mo ago
I think it is impossible to connect directly because MongoDB typically requires a TCP connection, and Workers don't support persistent connections like TCP, WebSockets
Ricky U
Ricky U3w ago
it is possible now within a worker, as workers support NET

Did you find this page helpful?