DEV Community

Peter Lau
Peter Lau

Posted on • Originally published at quickanswer.awesomefe.dev

3 1

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay