import pymongo


class MongoManager:
    __instance = None

    @staticmethod
    def getInstance():
        if MongoManager.__instance == None:
            MongoManager()
        return MongoManager.__instance

    def __init__(self):
        if MongoManager.__instance != None:
            raise Exception("This class is a singleton!")
        else:
            MongoManager.__instance = pymongo.MongoClient('127.0.0.1', port=27017, serverSelectionTimeoutMS=1000)
            db = MongoManager.__instance.AIC
            coll = db.metadata
            db.coll["identifier"]
            db.coll["sha512"]
            db.coll["location"]
            coll.create_index("identifier", unique=True)
            coll.create_index([("location", pymongo.GEO2D)])
