22 lines
735 B
Python
22 lines
735 B
Python
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['MovementLogs'].create_index("timestamp", expireAfterSeconds=3600)
|
|
database['ClimateLogs'].create_index("timestamp", expireAfterSeconds=3600)
|
|
database['LightLogs'].create_index("timestamp", expireAfterSeconds=3600) |