DEV Community


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

Peter Lau
Curious about everything about programming. Open mind to everything unfamiliar with. Raise qarabbit ( online.
Originally published at ・1 min read

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


    --uri "mongodb://<username>:<password>@
<ip or domain>:<port>/?authSource=
    -d <db> -c <collection> 

Maybe also works with mongo and mongoexport


Discussion (0)

Forem Open with the Forem app