Next.js Discord

Discord Forum

Couldnt connect to MongoDB !!!

Answered
Asian swamp eel posted this in #help-forum
Open in Discord
Asian swamp eelOP
couldnt connect to mongoDB
making CRUD App using mongoDB in Next.js
Answered by Double-striped Thick-knee
make sure that you have the correct connection string and try to connect to it from MongoDB Compass
View full answer

21 Replies

@Asian swamp eel couldnt connect to mongoDB making CRUD App using mongoDB in Next.js
Double-striped Thick-knee
have you passed connection string to mongoose.connect() ?
Asian swamp eelOP
import mongoose from "mongoose";

async function connectMongoDB() {
  try {
    await mongoose.connect(process.env.MONGODB_URI);
    console.log("Connected to MongoDB");
  } catch (error) {
    console.log(error);
  }
}

export default connectMongoDB;
 


yes !!!
Asian swamp eelOP
yes

MONOGODB_URI=mongodb+srv://<ID>:<PASSWORD>@cluster0.asnnm.mongodb.net/
crud_db

 
@Asian swamp eel yes js MONOGODB_URI=mongodb+srv://<ID>:<PASSWORD>@cluster0.asnnm.mongodb.net/ crud_db
Double-striped Thick-knee
bruh, there is a typo. it's MONGODB_URI not MONOGODB_URI 😆
Asian swamp eelOP
thx mate trying 😄
@Asian swamp eel Click to see attachment
Double-striped Thick-knee
this error is related to how your mongodb atlas is configured. you have to whitelist your ip to access mongodb.
Asian swamp eelOP
since i am using configuration of ip `0.0.0.0/0
@Asian swamp eel since i am using configuration of ip 0.0.0.0/0`
Double-striped Thick-knee
hmmm ok, did you write the database name at the end of connection string
<PASSWORD>@cluster0.asnnm.mongodb.net/myDatabase
Asian swamp eelOP
https://www.youtube.com/watch?v=wNWyMsrpbz0&t=3s
i am watching video from here !!!
Double-striped Thick-knee
make sure that you have the correct connection string and try to connect to it from MongoDB Compass
Answer
Asian swamp eelOP
ok trying !!!
Asian swamp eelOP
its a small issue that causing the error was VPN since twitter ban hi my country so i use twitter when i disconnect from VPN and try to POST data then work !!!
Asian swamp eelOP
Done !!!