DEV Community

loading...

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

Peter Lau
Curious about everything about programming. Open mind to everything unfamiliar with. Raise qarabbit (https://quickanswer.awesomefe.dev/about/) online.
Originally published at quickanswer.awesomefe.dev ・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

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:

Discussion (0)

Forem Open with the Forem app