You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Prisma连接MongoDB用filterJson特性时JsonFilter报path不存在错误如何解决

问题根因

Prisma 的 filterJson 预览特性的path参数仅对PostgreSQL的JSONB字段生效,MongoDB场景下的JsonFilter类型没有实现path相关属性,这是报错的核心原因。

解决方案

MongoDB 原生支持用点路径的方式查询JSON嵌套字段,调整查询语法即可实现需求:

  1. 单条件查询写法(对应你当前的循环逻辑)
for (const [key, value] of Object.entries(filters)) {
  const queryKey = `options.${key}`
  return await prisma.user.findMany({
    where: {
      [queryKey]: value
    }
  })
}
  1. 多条件批量查询写法(推荐,避免循环多次查询数据库)
const whereCondition = {}
Object.entries(filters).forEach(([key, value]) => {
  whereCondition[`options.${key}`] = value
})
// 一次查询匹配所有过滤条件
const users = await prisma.user.findMany({
  where: whereCondition
})

修改完代码后重新执行一次npx prisma generate确保客户端类型同步即可正常运行。

内容的提问来源于stack exchange,提问作者Lewis Morgans

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.23 17:45:01