DEV Community

Peter Lau
Peter Lau

Posted on • Originally published at quickanswer.awesomefe.dev

MongoDB |> server selection error: server selection timeout Type: ReplicaSetNoPrimary


Get a wired error message:

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

when using mongoimport command.

Fix that by adding argument --uri

Example:

mongoimport 
    --uri "mongodb://<username>:<password>@
<ip or domain>:<port>/?authSource=
<authSource>&authMechanism=SCRAM-SHA-1" 
    -d <db> -c <collection> 
    --file=./data.json

Maybe also works with mongo and mongoexport


References:

Top comments (0)