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 (0)