MongoDB first request takes ~45s on Windows
See original GitHub issueBug 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:
- Created 2 years ago
- Comments:13 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think that worked:
vs.
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.