I'm attempting to import json into an atlas db.
The attempt uses this code:
mongoimport --uri "mongodb://usr:pass#myurlname.uia8q.mongodb.net/paintura?retryWrites=true&w=majority" --collection products --file pathtojson
all parameters in the above are correct via the connect docs.
exact error is:
error connecting to host: could not connect to server: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: myurlname.uia8q.mongodb.net:27017, Type: Unknown, Last error: connection() error occured during connection handshake: dial tcp: lookup paintura.uia8q.mongodb.net: no such host }, ] }
For the user I have atlas admin selected so I assume it should have full privelege.
I also have cleared my ip in the ip list.
Any ideas what I'm missing?
Related
I have a Go program which uses Mongo DB. I run it from my home pc and I keep getting this error very often:
panic: server selection error: server selection timeout, current
topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr:
cluster0-shard-00-00.tvm1o.mongodb.net:27017, Type: Unknown, Last
error: connection() error occurred during connection handshake: dial
tcp
3.216.112.85:27017: i/o timeout }, { Addr: cluster0-shard-00-01.tvm1o.mongodb.net:27017, Type: Unknown, Last
error: connection() error occurred during connection handshake: dial
tcp 34.197.85.254:27017: i/o timeout }, { Addr:
cluster0-shard-00-02.tvm1o.mongodb.net:27017, Type: Unknown, Last
error: connection() error occurred during connection handshake: dial
tcp 18.206.5.2:27017: i/o timeout }, ] }
And this is the exact code where it breaks:
if err := clientMongo.Ping(context.TODO(), readpref.Primary()); err != nil {
panic(err)
}
I understand this is a connection timeout, but I don't understand how can this happen at all during a simple client connection. I made a speedtest and my current upload speed is 22 Mbps, I am not uploading big json arrays or anything. It happens always when I try to connect to the client. So I would like to know if this can be caused because my internet connection or something on Mongo's end?
You might need to add your IP to the whitelist of MongoDB.
A few things --
we would need to see the complete code for creating a connection. I'm going to assume you're using exactly what is in the documentation here?
You should try to connect with mongosh and Compass also. If you have problems with another tool, then the odds are it is your Atlas cluster OR your security settings on the cluster, rather than your application code.
that being said about 95% of the time the issue is whitelist or database users. do you have a user created in database access area of the UI that has admin/read/write any database? is your IP in the whitelist?
if 3 is good, and 2 doesn't work, there is free Atlas support available in the green chat button of the UI in MongoDB.
I'm running a mongo image in a container with this config:
version: '3'
services:
mongodb:
image: mongo
ports:
- '27017:27017'
environment:
- MONGO_INITDB_ROOT_USERNAME=user
- MONGO_INITDB_ROOT_PASSWORD=password
- MONGO_INITDB_DATABASE=microservices
volumes:
- ./docker-entrypoint-initdb.d/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
And I have started to build microservices with golang and I want to start dockerizing those as well to speed up the development process. However when I try to run this Dockerfile below it panics at the run test command with the error:
database url: mongodb://user:password#127.0.0.1:27017/microservices
server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: 127.0.0.1:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp 127.0.0.1:27017: connect: connection refused }, ] }
panic: server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: 127.0.0.1:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp 127.0.0.1:27017: connect: connection refused }, ] }
The db connection works since when I try to run the test from the go files, they pass. There only seems to be any problem when I try to run them from the container when building it up.
FROM golang:1.18 as build
WORKDIR /go/src/app
COPY . .
RUN go mod download
RUN go vet -v /go/src/app/...
RUN go test -v /go/src/app/...
RUN CGO_ENABLED=0 go build -o /go/bin/app/authsvc /go/src/app/authentication/main.go
FROM gcr.io/distroless/static-debian11
COPY --from=build /go/bin/app/authsvc /
COPY --from=build /go/src/app/authentication/.env /
CMD ["/authsvc"]
Change database url
try mongodb
database url: mongodb://user:password#mongodb:27017/microservices
So first of all you must check your default network ip with
docker network ls
Result
After get network id and use this command :
docker inspect <your network id>
Inside result schema get your Gateway ip
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "111.11.0.0/11",
"Gateway": "111.11.0.1"
}
]
}
and use that ip
database url: mongodb://user:password# < your Gateway ip > :27017/microservices
I am new with MongoDB and I have a test account on mongogb account. I am trying to export the database I have remotely and this has given me a lot of headaches. Can someone help me out on this please?
mongoexport \
--host="myDbUser:DataBas3Pwd#mongodb://cluster0.raiy3.mongodb.net" \
-d socialDeveloper \
-c posts \
--out social.json
When I run the code on my command line it returns the response:
2021-03-01T01:13:26.240+0100 could not connect to server: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: cluster0.raiy3.mongodb.net:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : dial tcp: lookup cluster0.raiy3.mongodb.net: no such host }, ] }
And here is where I got the connection details from on my mongoDb account
WHat do I need to change please?
Try:
mongoexport 'mongodb+srv://myDbUser:DataBas3Pwd#cluster0.raiy3.mongodb.net' --db=socialDeveloper --collection=posts --out=social.json
I am trying to use mongoimport my existing .json file into the cloud cluster. But I keep getting this error
error validating settings: incompatible options: --file and positional argument(s)
I have been on the cat with mongo for an hour and they have been no help to solve my issue. I think it has to do with --file drivers.json and it finding that file.
./mongoimport --host muleapp-shard-00-02-bxny3.mongodb.net:27017 --ssl --username srusso -password MuleApp2019 --authenticationDatabase admin --db Drivers --collection driver --type json --file drivers.json
error validating settings: incompatible options: --file and positional argument(s)
now I am getting a time out error:
2019-11-08T14:12:38.533-0500 error connecting to host: could not connect to server: server selection error: server selection timeout
current topology: Type: Single
Servers:
Addr: muleapp-shard-00-02-bxny3.mongodb.net:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : dial tcp 3.229.7.228:27017: i/o timeout
The first error could be due to long option password being provided using - rather than --. So the option could be provided as either of --password MuleApp2019 or -p MuleApp2019.
i tried to run MongoDB in docker-compose and connect my Go server with MongoDB in docker seem not to work for me, thought i already use mongodb:MyContanerName:27017
when i run my go server and then i tired to request on my client, the error something like this
2019/09/08 14:10:37 Unexpected error: rpc error: code = Internal desc = internal error: server selection error: server selection timeout
current topology: Type: Unknown
Servers:
Addr: mongo:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection(mongo:27017[-125]) connection is closed
i already did docker-compose up -d for my docker, and it was running on my docker ,
the full code is trigger here golang and mongodb