error connecting to host: could not connect to server: server selection error: server selection timeout current topology: Type: Single Servers
Asked Answered
P

5

9

I need to import a CSV file to mongoDB unfortunately i'm having below error:

    error connecting to host: could not connect to server: server selection error: server selection timeout
    current topology: Type: Single
    Servers:
    Addr: eaderline:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : dial tcp: lookup eaderline: no such host

my import string looks like that:

mongoimport --host Test-shard-0/test-shard-00-00-gceee.mongodb.net:27017,test-shard-00-01-gceee.mongodb.net:27017,test-shard-00-02-gceee.mongodb.net:27017 --ssl --username <username> --password <password> --authenticationDatabase admin --db EngineeringProject --collection FirstName --type csv -file "C:\Users\Ja\Desktop\INFA\ProjektInzynierski\DaneDBzMC\imiona.csv" -headerline

The funny part about this error is that, i was able to import data to mongodb a 2 weeks ago by similar string which looks like this one below, and today it's imposible, why?

mongoimport --host Test-shard-0/test-shard-00-00-gceee.mongodb.net:27017,test-shard-00-01-gceee.mongodb.net:27017,test-shard-00-02-gceee.mongodb.net:27017 --ssl --username <username> --password <password> --authenticationDatabase admin --db Test2 --collection COL_First --type csv -file "C:\Users\Ja\Desktop\Przykladowy\Mapy\liczba.csv" -headerline

Does anyone see any mistake?

I have checked the port 27017 on my machine is free, maybe there is something going on on the cluster side? Is there a way to launch an empty import, just for checking the connection?

Pleione answered 19/12, 2019 at 16:8 Comment(0)
D
9

use URI command It works for me in windows command line

mongoimport --uri "mongodb://**user:passwd**@***host:port***/database?ssl=true&replicaSet=**replicasetneme**"
-c **collection** --file **csvFile** --fields **fields with comma separated**
Diluvial answered 21/1, 2020 at 2:42 Comment(0)
P
2

Finally I was able to import my CSV file via mongodb GUI client, Compass.

In the meantime i bumped into another issue. Compass connect do the cluster showed the DBs, but didn't show the collections. It turned out that my user had a bad role. I deleted the user and add it once again, and it worked, I could see the collections also.

After that I was able to import my CSV file.

Pleione answered 19/12, 2019 at 17:29 Comment(0)
U
0

1.First make sure that db port 27017 is not used by other local server instance

2.If using cloud, then log in to console and Click on Cluster Name then Command Line Tools copy the mongo import command which will look some thing like

mongoimport --host DemoCluster-shard-0/democluster-shard-00-00-5zjhn.mongodb.net:27017,democluster-shard-00-01-5zjhn.mongodb.net:27017,democluster-shard-00-02-5zjhn.mongodb.net:27017 --ssl --username <USERNAME>--password <PASSWORD> --authenticationDatabase admin --db <DATABASE> --collection <COLLECTION> --type <FILETYPE> --file <FILENAME>

Note: Pass TYPE as --jsonArray if file contains json aray

Urtication answered 12/4, 2020 at 4:46 Comment(0)
C
0

Every time I face this type of error:

error connecting to host: could not connect to server...

It's because MongoDB didn't start. Try to start it manually. As a windows user: Mongodb error connecting to host

Commensurate answered 16/5, 2021 at 7:8 Comment(0)
R
0

For me it was the --ssl option. It did not matter if I was passing it or not in the connection string, it needed to be passed as a parameter. The following command worked.

mongorestore --noIndexRestore --ssl --db database --verbose --uri mongodb://user:[email protected]:10255/?retrywrites=false --archive < documents.dump

This one did not

mongorestore --noIndexRestore --db database --verbose --uri mongodb://user:[email protected]:10255/?retrywrites=false&ssl=true --archive < documents.dump

The same issue is also for mongoimport

Rabbinical answered 6/3, 2023 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.