Couldnt connect to MongoDB !!!
Answered
Asian swamp eel posted this in #help-forum
Asian swamp eelOP
couldnt connect to mongoDB
making CRUD App using mongoDB in Next.js
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
21 Replies
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 !!!
Double-striped Thick-knee
is it in your .env
MONGODB_URI
Asian swamp eelOP
yes
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 😄
still got error !!!
Double-striped Thick-knee
this error is related to how your mongodb atlas is configured. you have to whitelist your ip to access mongodb.
https://www.youtube.com/watch?v=KW6A5UhOa7c&t=139s you can watch this video
Asian swamp eelOP
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
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 !!!
Double-striped Thick-knee
Alright, Mark Solution
Asian swamp eelOP
Done !!!