New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prisma Mongo Panic called Option::unwrap()
on a None
value
#8598
Comments
Having a similar issue when trying to run this query:
I get this error: The two related models look like this:
Any ideas on what might be wrong or is this definitely a bug? |
Weirdly this does work:
This fixes the issue that was blocking me but I'm still wondering why I can't just use |
Hey there, I wasn't able to reproduce this error on 3.11.0. Do you mind trying again on the latest version? Given the following schema: datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["mongodb"]
}
model Cluster {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
followers User[] @relation("ClusterFollowers", fields: [followerIDs], references: [id])
followerIDs String[] @db.ObjectId
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
clusterFollowers Cluster[] @relation("ClusterFollowers", fields: [clusterFollowerIds], references: [id])
clusterFollowerIds String[] @db.ObjectId
} And the following script: import { PrismaClient, Prisma } from "@prisma/client"
const prisma = new PrismaClient()
async function main() {
await prisma.$connect()
await prisma.user.deleteMany()
await prisma.cluster.deleteMany()
const u1 = await prisma.user.create({
data: {
name: "Bob",
},
})
const u2 = await prisma.user.create({
data: {
name: "Alice",
},
})
const c1 = await prisma.cluster.create({
data: {
name: "Tennis",
followers: {
connect: [
{
id: u1.id,
},
{
id: u2.id,
},
],
},
},
})
const c2 = await prisma.cluster.create({
data: {
name: "Soccer",
followers: {
connect: {
id: u2.id,
},
},
},
})
const c3 = await prisma.cluster.create({
data: {
name: "Basketball",
followers: {
connect: {
id: u1.id,
},
},
},
})
const clusters = await prisma.cluster.findMany({
where: {
followers: { some: { id: u1.id } },
},
})
console.log(clusters)
}
main()
.catch(console.error)
.finally(() => prisma.$disconnect()) Running this, you get: $ ts-node index.ts
[
{
id: '621ff2227ee6d06d1682f0c0',
name: 'Tennis',
followerIDs: [ '621ff2227ee6d06d1682f0be', '621ff2227ee6d06d1682f0bf' ]
},
{
id: '621ff2237ee6d06d1682f0c2',
name: 'Basketball',
followerIDs: [ '621ff2227ee6d06d1682f0be' ]
}
] Version $ npx prisma version
npx prisma version
Environment variables loaded from .env
prisma : 3.11.0-dev.30
@prisma/client : 3.11.0-dev.30
Current platform : darwin
Query Engine (Node-API) : libquery-engine 4cac12afbeef2fa3eedf1cb87c79bc15e2648836 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 4cac12afbeef2fa3eedf1cb87c79bc15e2648836 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 4cac12afbeef2fa3eedf1cb87c79bc15e2648836 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 4cac12afbeef2fa3eedf1cb87c79bc15e2648836 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 4cac12afbeef2fa3eedf1cb87c79bc15e2648836
Studio : 0.458.0
Preview Features : mongoDb |
Ping @CryogenicPlanet @ezeikel |
Closing, but happy to re-open if this pops back up. |
@janpio @matthewmueller The issue I was having turned out to be on my side - when calling So all good from me |
Hey I am unable to get this query to work and would love some help
Whereas the below query works fine
I have tried doing something like and this give another error
EDIT
This causes an error when using prisma studio to view either the
Users
orProjects
modelsSo it is definitely a problem with the schema or how it is being read. (I am fairly new to prisma so this schema might be wrong, but I think the compiler should probably throw an error for this)
EDIT 2
We ended up moving to postgres and this schema works fine, so this is a bug with mongo specifically
Schema
Versions
Query
Logs
The text was updated successfully, but these errors were encountered: