Error: MongoDB error Server selection timeout: No available servers. #11929
-
Hi, I tried to run mongo on Docker, but when I type prisma db push I get this error, can you help? Connectiong String: mongodb://username:password@localhost:27017/akillisatici?authSource=admin&retryWrites=true&w=majority docker-compose.yml version: "3.8"
networks:
akillisatici-net:
name: akillisatici-net
volumes:
akillisatici-2.mongo:
akillisatici-1.mongo:
akillisatici-0.mongo:
services:
akillisatici-2.mongo:
hostname: akillisatici-2.mongo
container_name: akillisatici-2.mongo
image: mongo
entrypoint:
[
"/usr/bin/mongod",
"--keyFile",
"/data/file.key",
"--replSet",
"rs",
"--journal",
"--bind_ip_all",
]
ports:
- "27018:27017"
restart: always
networks:
- akillisatici-net
volumes:
- "akillisatici-2.mongo:/data/db"
- "./.docker/file.key:/data/file.key"
akillisatici-1.mongo:
hostname: akillisatici-1.mongo
container_name: akillisatici-1.mongo
image: mongo
entrypoint:
[
"/usr/bin/mongod",
"--keyFile",
"/data/file.key",
"--replSet",
"rs",
"--journal",
"--bind_ip_all",
]
ports:
- "27019:27017"
restart: always
networks:
- akillisatici-net
volumes:
- "akillisatici-1.mongo:/data/db"
- "./.docker/file.key:/data/file.key"
akillisatici-0.mongo:
hostname: akillisatici-0.mongo
container_name: akillisatici-0.mongo
image: mongo
command: bash -c "/usr/bin/mongod --keyFile /data/file.key --replSet rs --journal --bind_ip_all"
ports:
- "27017:27017"
links:
- akillisatici-1.mongo:akillisatici-1.mongo
- akillisatici-2.mongo:akillisatici-2.mongo
restart: always
networks:
- akillisatici-net
volumes:
- "akillisatici-0.mongo:/data/db"
- "./.docker/setup.sh:/scripts/setup.sh"
- "./.docker/file.key:/data/file.key"
setup.sh #!/bin/bash
mongo <<EOF
var cfg = {
"_id": "rs",
"version": 1,
"members": [
{
"_id": 0,
"host": "akillisatici-0.mongo:27017",
"priority": 2
},
{
"_id": 1,
"host": "akillisatici-1.mongo:27017",
"priority": 0
},
{
"_id": 2,
"host": "akillisatici-2.mongo:27017",
"priority": 0
}
]
};
rs.initiate(cfg, { force: true });
//rs.reconfig(cfg, { force: true });
rs.status();
EOF After prisma db push command:
|
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 25 replies
-
Hey @BEDIRHANSAMSA 👋, It seems like Prisma is having trouble finding and connecting to the DB. Are you able to connect to the database using a Mongo UI or some other method using the same connection string? Thanks! |
Beta Was this translation helpful? Give feedback.
-
I have solved this question through these 3 steps.
|
Beta Was this translation helpful? Give feedback.
-
Same problem! prisma: ^v5.0.0 |
Beta Was this translation helpful? Give feedback.
-
directConnection true is the solution for that |
Beta Was this translation helpful? Give feedback.
-
I was also having this error, I managed to solve it by adding my ip address there in the network access configuration |
Beta Was this translation helpful? Give feedback.
-
These types of problems usually have a simple solution. Add your own current IP address from the Network Access page from the Mongodb left sidebar menu. If the problem persists, enter 0.0.0.0 in the IP address section. The reason why I experienced this error was because my IP address was renewed when my modem was turned off and on. I reluctantly experienced that this security measure of mongodb was successful :) |
Beta Was this translation helpful? Give feedback.
-
For me the problem was using the monorepo setup with microservices, make sure when having different |
Beta Was this translation helpful? Give feedback.
-
mongodb://hoangnam1x0:131312htquynh@localhost:27017/site?directConnection=true fix it with directConnection=true Does anyone have a better solution? |
Beta Was this translation helpful? Give feedback.
-
In my case I had different ports set for mongo service:
and while I can connect to the database from host using 27019, when connecting from another service I had to use 27018, otherwise it fails to connect. |
Beta Was this translation helpful? Give feedback.
-
this is not solved, ive issue where its been running for 3days no problem, and out of blue this happen. does this has todo with DNS server? |
Beta Was this translation helpful? Give feedback.
-
i think the directconnection is not supported
…On Thu, 6 Jun 2024, 3:08 pm Roshan6354, ***@***.***> wrote:
@AdelMohammed8 <https://github.com/AdelMohammed8> in your .env
Hi,
I'm still getting the error like database URL string is invalid when i
type npx prisma db push can you please help !!
DATABASE_URL = "mongodb+srv://:@
cluster0.vpcsk0a.mongodb.net/estate?replicaSet=rs0&retryWrites=true&w=majority&directConnection=true&appName=Cluster0
"
—
Reply to this email directly, view it on GitHub
<#11929 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC65TOWW7AXLV7G26ZO3YDZGADHFAVCNFSM5O4OMET2U5DIOJSWCZC7NNSXTOKENFZWG5LTONUW63SDN5WW2ZLOOQ5TSNRYGYYTCNY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
directConnection true is the solution for that