问题
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?
回答1:
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**
回答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.
来源:https://stackoverflow.com/questions/59413297/error-connecting-to-host-could-not-connect-to-server-server-selection-error-s