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

使用Prisma+MongoDB Atlas创建用户时遇‘empty database name not allowed’错误

Prisma + MongoDB Atlas 创建用户时出现"empty database name not allowed"错误

在Node.js应用中使用Prisma和MongoDB Atlas创建用户时,触发empty database name not allowed错误,接口返回提示Error creating user。

复现步骤

  • 向/api/register端点发送POST请求,请求体携带username、email、password用户数据
  • 应用尝试通过Prisma执行用户创建操作

相关代码片段(auth.controller.js)

export const register = async (req, res) => {
  // ... (提取用户数据的代码)

  try {
    const newUser = await prisma.user.create({
      data: {
        username,
        email,
        password: hashedPassword,
      },
    });
    // ... (成功处理逻辑)
  } catch (error) {
    console.error(error);
    res.status(500).json({ message: "Error creating user" });
  }
};

已完成的排查操作

  • 确认.env文件的MongoDB连接URL中包含正确的数据库名称
  • 检查控制台日志,未发现Prisma或数据库连接相关的额外错误信息
  • 反复核对Postman请求参数,确保用户创建数据格式正确
  • 修改配置后已重启应用服务器

依赖版本

"dependencies": { 
  "@prisma/client": "^5.15.0", 
  "bcrypt": "^5.1.1", 
  "express": "^4.19.2", 
  "prisma": "^5.15.0" 
}

内容的提问来源于stack exchange,提问作者youssef-lou

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 17:32:01