7

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?

3 Answers 3

2

There are some options.

  1. 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().

  2. 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.

Sign up to request clarification or add additional context in comments.

Comments

1

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)

Comments

1

You can try out the MongoDB DataAPI. I made a wrapper here: https://www.npmjs.com/package/mongo-rest-client

Do note that it is limited to some extent as the Data API does not support all the functionalities (like transactions).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.