MoonBoi9001
MoonBoi9001

Reputation: 65

Trying to connect to MongoDB with pymongo but I'm getting ServerSelectionTimeoutError because the target machine actively refused it

Here's my code

from pymongo import MongoClient
ip = '127.0.0.1'
port = 27017
dbName = "mydb"
DimensionsCollection = "Dimensions"
client = MongoClient(ip,port)
db = client[dbName]

try to insert data into DimensionsCollection

db[DimensionsCollection].insert_many([
    {"Width":10.0, 'Length':15.2, 'Height':20.1,'Units':"cm"},
    {"Width":5.0, 'Length':7.2, 'Height':12.6,'Units':"cm"}
    ])

get the following error

ServerSelectionTimeoutError: 127.0.0.1:27017: [WinError 10061] 
No connection could be made because the target machine actively refused it, Timeout: 30s,
Topology Description: <TopologyDescription id: 610855273c445f94a29bfa02, topology_type: 
Single, servers: [<ServerDescription ('127.0.0.1', 27017) server_type: Unknown, rtt: None, 
error=AutoReconnect('127.0.0.1:27017: [WinError 10061] No connection could be made because 
the target machine actively refused it')>]>

Anyone know what's going on here?

Upvotes: 0

Views: 1119

Answers (1)

Eric McKeeth
Eric McKeeth

Reputation: 357

Check the answers here: Errno 10061 : No connection could be made because the target machine actively refused it ( client - server )

Most things that could be causing your error are discussed in the comments/answers there.

Upvotes: 1

Related Questions