Path does not exist in JsonFilter

Viewed 136

Not sure what's up. Using Prisma with a mongoDB connection. Trying to search the JSON tree for specific values that match the [key, value] from the loop. I haven't been able to get far enough to see if this implementation will work (I don't think it will) because the path property keeps giving an error. Below is my schema.prisma file and the error message being given back from the call back.

generator client {
  provider        = "prisma-client-js"
  previewFeatures = [ "mongoDb", "filterJson"]
}

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

model User {
  id       String @id @default(dbgenerated()) @map("_id") @db.ObjectId
  email    String
  options  Json
  password String
  role     String
}

Invalid `.findMany()` invocation 

for (const [key, value] of Object.entries(filters)) {
     return await prisma.user
→     .findMany({
           where: {
             options: {
               path: key,
               ~~~~
               equals: value
             }
           }
         })

Unknown arg `path` in where.options.path for type JsonFilter. Did you mean `not`? Available args:
type JsonFilter {
  equals?: Json
  not?: Json
}

Have ran npx prisma generate several times. Included the "filterJson" feature as documented. Have googled everything I can and I can't seem to find out where I'm going wrong.

Any help?

1 Answers

I think that mongo DB does not support the filter on json field and/or the underlying functionality is not supported by prisma.

(https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#filter-on-a-json-field)

The doc says

The implementation of Json filtering differs between connectors:

  • The MySQL connector uses MySQL's implementation of JSON path The
  • PostgreSQL connector uses the custom JSON functions and operators supported in version 12 and earlier

The functionnality seems to be only supported for postgre >= 12 and mysql

Edit : find this : https://github.com/prisma/prisma/discussions/10592

saying

Hey @LewisMorgans , this isn't available yet.

Related