import pymongo
import sys

class EchoDB:

    # Connect to MongoDB
    try:
        print('Connecting to MongoDB Database...')
        mongo_client = pymongo.MongoClient('mongodb://admin:ASnick1AS@172.16.100.244:27017/?authSource=admin')
        print('Connected to MongoDB Database!')
    except:
        print('Error occured while connecting to MongoDB Database!')
        print(sys.exc_info()[0])
        quit()
    
    # Select Database
    database = mongo_client['Echo']

    # Create Indexes
    database['MovementLog'].create_index("timestamp", expireAfterSeconds=10)
    database['ClimateLog'].create_index("timestamp", expireAfterSeconds=10)
    database['LightLog'].create_index("timestamp", expireAfterSeconds=10)