DEV Community

Deyan Petrov
Deyan Petrov

Posted on

Here is what took me an hour to sort with Prisma today.

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);
};
Enter fullscreen mode Exit fullscreen mode

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
}
Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
user64bit profile image
Arth

and after one hour of debugging, I found this post.

Collapse
 
artgurianov profile image
Art

SAVED ME

Collapse
 
ali_sufiyan_123 profile image
Ali Sufiyan

You are a life saver thanks man.

Collapse
 
thibault_roth_427e6597165 profile image
Thibault ROTH

I've been trying to solve this for 2 hours, thank you.

Collapse
 
rotrixx profile image
RotrixX

GOD BLESS YOU

Collapse
 
neeraj_kashetty_6438a274a profile image
Neeraj Kashetty

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!