So today I started learning a bit more about Prisma using MongoDB. But I encountered and issue that seemed mind boggling.
TypeError: Cannot read properties of undefined (reading 'findMany')
TLDR: Restart the server after changing Prisma Schemas.
I was trying to run the following code:
const breakTimeLog = async (req: NextApiRequest, res: NextApiResponse) => {
const tests = await prisma.breakTimeLog.findMany();
res.status(200).json(tests);
};
The reason that it was mind boggling is that if I would replace breakTimeLog
with user
it worked fine. I tried renaming and regenerating the schema as I thought it was a naming issue due to camel case. That was the only thing I could see being different. But no luck ):
Here is the Schema itself
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
fname String
lname String
breakTimeLogs BreakTimeLog[]
}
model BreakTimeLog {
id String @id @default(auto()) @map("_id") @db.ObjectId
date DateTime
timeInSeconds Int
timeOfBreak DateTime @default(now())
user User @relation(fields: [userId], references: [id])
userId String @db.ObjectId
}
Every place I looked suggested to generate the schema again or that there is a spelling issue. After an hour on the google rabbit hole I gave up and started hacking at it with random stuff.
Here is the twist I did not restart the server after I created the new model after doing so everything is working fine!
Top comments (6)
and after one hour of debugging, I found this post.
SAVED ME
You are a life saver thanks man.
I've been trying to solve this for 2 hours, thank you.
GOD BLESS YOU
I tried for an hour and went to the gym thinking about it, I've done my whole workout thinking on why ? why?.. But after i found your post i felt it was so basic.. haha Thanks man!