innovationOUtside / tm351vm-binder

See if we can generate a Binder/repo2docker build of the TM351 VM
MIT License
7 stars 4 forks source link

MongoDB doesn't connect notebook 14.1 #18

Closed undercertainty closed 3 years ago

undercertainty commented 4 years ago

The connection is set up with:

client = pymongo.MongoClient('mongodb://localhost:27351/')

Then we try:

try:
    client.drop_database(dw_db)
except NameError:
    print("DB doesn't exist yet.")

and get the error:

ServerSelectionTimeoutError: localhost:27351: [Errno 111] Connection refused
psychemedia commented 3 years ago

In Docker container, the Mongo server runs on the default port:

from pymongo import MongoClient

# Open a connection to the Mongo server, open the accidents database and name the collections of accidents and labels
MONGO_PORT = 27017
MONGO_CONNECTION_STRING = f'mongodb://localhost:{MONGO_PORT}/'

client = MongoClient(MONGO_CONNECTION_STRING)

# Create a test database
db = client.testdb