I’m learning next 13, and I’m trying to do a simple api request that bring me the data from the database,but I’ve received an empty array back from the database,
I’m trying to achieve this using Prisma
this is my prisma schema:
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Toy {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
price String
labels String[]
createdAt String
inStock Boolean
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
password String
username String
fullName String
isAdmin Boolean
}
this is prisma client instense
import { PrismaClient } from '@prisma/client'
const prisma = global.prismadb || new PrismaClient()
if (process.env.NODE_ENV !== 'production') global.prismadb = prisma
export default prisma
this is the database request
export async function GET() {
try {
const res = await prisma.toy.findMany()
const data = await res.json()
return NextResponse({ data })
} catch (err) {
console.log('Error', err)
}
}
It is return an empty array, but there is data on the database, and even when I try to consoloe.log() the data it is empty array
this is my DATABASE_URL and of course replaced with the username and password:
DATABASE_URL="mongodb+srv://<username>:<password>@cluster0.qplxj.mongodb.net/itemDB