First connection to Mongo Atlas takes a long time

I’m using Mongo Atlas with Prisma. Whenever I launch my project, it takes about 3 minutes for database to connect, and in this period of time, I can’t see anything in Mongo Atlas’ connection tab. I’ve tried Prisma’s logger, no error prints at all. Interestingly, it connects but it just takes time.

It eventually connects, but this issue with connection time makes using hot reload quite hard. I’ve tried allowing incoming Node apps in Advanced Firewall Settings, and my firewall is disabled. Actually I couldn’t find a lot of people experiencing this, so I couldn’t try much to be honest. And to note, when somebody else tries to launch exact same code, their database starts working instantly.


I am not sure what could be wrong as the problem may be in the connection options, in some prisma setting, or some networking issue.

Also, normally the connection tries should time out after 30s (or close to), so maybe the connection request is ‘delayed’ because is waiting some other function in the stack to execute, before actually trying to connect.

But maybe you can include the connection string (replace clusterID, username, password), and the options ?

And also potentially relevant pieces of code.

I have only these regarding connection code, Prisma handles the rest. Since my friends can’t reproduce this issue with exact same code, I’m suspicious about whether it’s about the code or not.


Quick note: Username and admin placeholders are replaced on my original file.

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["mongoDb"]
1 Like