Replies: 1 comment
-
I also added a console.log in the snippets/new route and it indeed runs 2 times. Any idea why my api route runs 2 times when I make exactly one request (also checked in chrome devtools network tab)? I pushed to vercel and tried production. On production the console.log gets called only one time (according to vercel function log). But none entries gets added to my db (env variables set on vercel, i dont get it) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys,
I'm using mongodb with next.js api routes. I have it set up like this article from vercel itself: https://vercel.com/guides/deploying-a-mongodb-powered-api-with-node-and-vercel
But unfortunately when I insert one single object and return it there are like 15 open connections and it adds the document 2 times.
Here is all I do when I go to
/api/snippets/new
:The
connectToDatabase
is exactly the same as from the vercel example but with my links and env variables.I use MongoAtlas and this all happens in dev mode (localhost:3000). I guess in prod it would work, since the serverless function on vercel would shut down itself or something like that.
Can you please help me out here and how I use it 100 % correctly with next.js? The number one problem is that it adds the document 2 times. About the 15 connections, I could live with that but I think the 2 problems are connected.
I also use next-auth in my project that also uses mongo with typeORM
BIG UPDATE:
I tried now the official example from the official vercel github repo examples repo (added it to my project): https://github.com/vercel/next.js/tree/canary/examples/with-mongodb-mongoose
My
/api/snippets/new
now looks like this:Still the same problem. It always inserts the document 2 times. I don't get it.
Any ideas how to solve this? :) I'm so close
Beta Was this translation helpful? Give feedback.
All reactions