I am experiencing long cold start times when making a new document using my API on Vercel Serverless Functions. To Speed up the request, I want to run the API on Vercel Edge Functions, but the edge runtime does not support the MongoDB official Node driver. Is there any way around this limitation/an unofficial driver I can use?
2 Answers
One way is to use Prisma ORM with MongoDB. Vercel's Edge functions do not support most of Node.js APIs (ref: https://vercel.com/docs/concepts/functions/edge-functions).
However, you can get around it by using their Prisma Data Proxy which allows you to interact with your database over HTTP. (ref: https://www.prisma.io/blog/database-access-on-the-edge-8F0t1s1BqOJE)

- 144
- 3
There are some options.
Assuming you're hosting at MongoDB, you can use their Atlas Data API, which is an HTTP REST API. You'll need to rewrite your database query / operation code to use
fetch()
.I just created mongodb-rest-relay, which is a drop-in-replacement (i.e. API compatible) for the
mongodb
driver, but relays each request over HTTP. Currently the idea is to have the other end of the relay running on serverless infrastructure, but I might also add an option to use Atlas Data API as an endpoint. I'm still experimenting with what works best.

- 1,431
- 15
- 16