title: Mongodb pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused, Timeout: 30s,
body: <p>I am trying to locally connect to my db. I've established a connection to the database on MongoDB Compass, but when I run my simple code, I get this error:</p>
  <blockquote>
  <p>pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno
  111] Connection refused, Timeout: 30s, Topology Description:
  &lt;TopologyDescription id: 60e2b31fab1da2bb146bb38c, topology_type:
  Single, servers: [&lt;ServerDescription ('localhost', 27017) server_type:
  Unknown, rtt: None, error=AutoReconnect('localhost:27017: [Errno 111]
  Connection refused')&gt;]&gt;
  root@LAPTOP-8OKVP35I:/portfolio/myProjects/webDevelopment/shopify_db#</p>
  </blockquote>
  <p>This is the code I am running:</p>
  <pre><code>import pymongo
  from pymongo import MongoClient
  
  client = pymongo.MongoClient()
  db = client[&quot;Shopper_Info&quot;]
  my_collection = db[&quot;Names&quot;]
  shopper_data = {'name': 'Yoni', 'email': 'test@gmail.com'}
  
  my_collection.insert_one(shopper_data)
  
  results= collection.find({&quot;name&quot;: 'Yoni'})
  
  for result in results:
  print(result)
  </code></pre>