question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MongoDB first request takes ~45s on Windows

See original GitHub issue

Bug description

The first request takes a long time because prisma is trying to connect to the database for the first time, when I send the second request after the first request is finished, I get a response in a very short time. How can i fix this?

How to reproduce

Expected behavior

No response

Prisma information

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

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

model Customer {
  id                  String                @id @default(dbgenerated()) @map("_id") @db.ObjectId
  firstName           String
  lastName            String
  phone               String
  email               String                @unique
  password            String
  createdAt           DateTime              @default(now())
  updatedAt           DateTime              @updatedAt
  CurrentAccount      CurrentAccount[]
  CurrentAccountGroup CurrentAccountGroup[]
}

model CurrentAccountGroup {
  id             String           @id @default(dbgenerated()) @map("_id") @db.ObjectId
  customerId     String           @db.ObjectId
  customer       Customer         @relation(fields: [customerId], references: [id])
  name           String
  createdAt      DateTime         @default(now())
  updatedAt      DateTime         @updatedAt
  CurrentAccount CurrentAccount[]
}

model CurrentAccount {
  id                    String              @id @default(dbgenerated()) @map("_id") @db.ObjectId
  customerId            String              @db.ObjectId
  customer              Customer            @relation(fields: [customerId], references: [id])
  currentAccountGroupId String              @db.ObjectId
  currentAccountGroup   CurrentAccountGroup @relation(fields: [currentAccountGroupId], references: [id])
  status                Boolean             @default(true)
  title                 String
  authorizedName        String
  authorizedSurname     String
  authorizedPhone       String
  authorizedEmail       String
  phone                 String
  email                 String
  address               String
  province              String
  district              String
  taxOffice             String
  taxNumber             String
  buyingDiscount        Decimal             @default(0)
  sellingDiscount       Decimal             @default(0)
  specialCode           String
  note                  String
  riskLimit             Decimal             @default(0)
  totalDebt             Decimal             @default(0)
  credit                Decimal             @default(0)
  balance               Decimal             @default(0)
  createdAt             DateTime            @default(now())
  updatedAt             DateTime            @updatedAt
}

Environment & setup

  • OS: Windows 11
  • Database: MongoDB
  • Node.js version: 16.13.1

Prisma Version

3.8.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
janpiocommented, Feb 18, 2022

I think that worked:

λ npx prisma@3.10.0-dev.57 db pull --url mongodb+srv://prisma:prisma@cluster0.bu2lt.mongodb.net/test?retryWrites=true&w=majority
Prisma schema loaded from prisma\schema.prisma
Environment variables loaded from .env
Datasource "db"

Introspecting …

✔ Introspected 1 model and wrote it into prisma\schema.prisma in 123.33s

Run npx prisma generate to generate Prisma Client.

vs.

λ npx prisma@3.10.0-dev.58 db pull --force --url mongodb+srv://prisma:prisma@cluster0.bu2lt.mongodb.net/test?retryWrites=true&w=majority
Prisma schema loaded from prisma\schema.prisma
Environment variables loaded from .env
Datasource "db"

Introspecting …

✔ Introspected 1 model and wrote it into prisma\schema.prisma in 3.63s

Run npx prisma generate to generate Prisma Client.
2reactions
janpiocommented, Feb 15, 2022

This is really bad on Windows, and we should really figure out if there is some good guidance we can give Windows users. They will really hate using MongoDB from Windows (as I just do while I am reproducing a few older issues).

Update, we tested the workaround mentioned via the links above: Before: ✔ Introspected 3 models and wrote them into prisma\schema.prisma in 125.38s After: ✔ Introspected 3 models and wrote them into prisma\schema.prisma in 5.34

Figuring out the details next.

Read more comments on GitHub >

github_iconTop Results From Across the Web

First query very slow, second - fast - M201 - MongoDB
What happens is that when I run the query first time, it takes about 90 seconds but then the second run takes about...
Read more >
MongoDB Limits and Thresholds
For featureCompatibilityVersion set to "4.4" or greater, MongoDB raises the limit for unsharded collections and views to 255 bytes, and to 235 bytes...
Read more >
$first (aggregation accumulator) — MongoDB Manual
Returns the value that results from applying an expression to the first document in a group of documents. Only meaningful when documents are...
Read more >
Getting data from query result taking a long time - MongoDB
I have a query which works fine but when running against a lot of data and wide date range it can take many...
Read more >
Read Data from MongoDB With Queries — Start with Guides
Even though the mainAtmosphere field is an array, you can use a strict equality query because MongoDB treats arrays as first-class types.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found