P
Prisma3mo ago
In&Out

Connecting prisma with mongodb issue

Hello, been following docs, used nextjs and i get this error.
4 Replies
In&Out
In&Out3mo ago
"use server";

import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();

async function Page() {
await prisma.user.create({
data: {
name: "Rich",
email: "hello@prisma.com",
posts: {
create: {
title: "My first post",
body: "Lots of really interesting stuff",
slug: "my-first-post",
},
},
},
});
const allUsers = await prisma.user.findMany({
include: {
posts: true,
},
});
console.dir(allUsers, { depth: null });

return <div>Page</div>;
}

export default Page;
"use server";

import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();

async function Page() {
await prisma.user.create({
data: {
name: "Rich",
email: "hello@prisma.com",
posts: {
create: {
title: "My first post",
body: "Lots of really interesting stuff",
slug: "my-first-post",
},
},
},
});
const allUsers = await prisma.user.findMany({
include: {
posts: true,
},
});
console.dir(allUsers, { depth: null });

return <div>Page</div>;
}

export default Page;
DATABASE_URL="mongodb+srv://name:password@cluster0.cnmfhut.mongodb.net/"
DATABASE_URL="mongodb+srv://name:password@cluster0.cnmfhut.mongodb.net/"
This is the error i get
Raw query failed. Code: `unknown`. Message: `Kind: Command failed: Error code 8000 (AtlasError): empty database name not allowed
Raw query failed. Code: `unknown`. Message: `Kind: Command failed: Error code 8000 (AtlasError): empty database name not allowed
How do I fix this?
Nurul
Nurul3mo ago
Hey 👋 You need to add a database name in your connection string DATABASE_URL="mongodb+srv://name:password@cluster0.cnmfhut.mongodb.net/your_db_name"
In&Out
In&Out3mo ago
My issue was I didn't make a container, fixed it, thank you
Nurul
Nurul3mo ago
I am glad to hear that the issue is resolved now!