user3777
user3777

Reputation: 39

unable to connect to mongodb atlas in 2023

`currently i am working on a MERN stack project. i want to use mongodb atlas as a cloud database but i can't connect to mongodb, when i try to connect i got the following error message.

MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://www.mongodb.com/docs/atlas/security-whitelist/ at _handleConnectionErrors (C:\Users\gedi\Desktop\stephan\car\server\node_modules\mongoose\lib\connection.js:755:11) at NativeConnection.openUri (C:\Users\gedi\Desktop\stephan\car\server\node_modules\mongoose\lib\connection.js:730:11) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async mongodb (C:\Users\gedi\Desktop\stephan\car\server\config\db.js:4:3) { reason: TopologyDescription { type: 'ReplicaSetNoPrimary', servers: Map(3) { 'ac-walbciw-shard-00-00.rhayeki.mongodb.net:27017' => [ServerDescription], 'ac-walbciw-shard-00-01.rhayeki.mongodb.net:27017' => [ServerDescription], 'ac-walbciw-shard-00-02.rhayeki.mongodb.net:27017' => [ServerDescription] }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: 'atlas-m5db59-shard-0', maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null },

i do have list my ip address and even i was trying to use access any where option from ip whitelist options in mongodb atlas.
in my country connections not working with out a vpn. is there any way to connect mongodb atlas with 
vpn connected.

here is my db.js file

const mongoose = require("mongoose");
async function mongodb() {
   await mongoose.connect("mongodb+srv://user: 
   [email protected]/? 
   retryWrites=true&w=majority", { useNewUrlParser: false });
   console.log("___________database connected___________");
 }
mongodb().catch((err) => console.log(err));

module.exports = mongoose;


this is the place where i use exported mongoose module from db.js

const mongoose = require("./../config/db");

const schema = new mongoose.Schema({
  carPhoto: String,
  mark: String,
  price: Number,
  ac: String,
  model: String,
  door: String,
  transmission: String,
  fuel: String,
  year: String,
  active: { type: Boolean, default: true },
  status: { type: String, default: "available" },
});

exports.Car = mongoose.model("car", schema);

any help i am stack on this problem for 2 days`

Upvotes: 2

Views: 307

Answers (0)

Related Questions