-
Notifications
You must be signed in to change notification settings - Fork 16
/
ConfigDB.py
31 lines (22 loc) · 1.02 KB
/
ConfigDB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from pymongo import MongoClient
from src.Config import dbUser, dbPwd,dbHost, dbPort, dbName, collection
print (dbUser, dbPwd)
class ConfigDB:
client = MongoClient(dbHost, username=dbUser, password=dbPwd, serverSelectionTimeoutMS=3000)
db = client[dbName]
collection = db[collection]
def _findAll(self):
""" Return all subdomains """
return self.collection.find()
def _add(self, target):
""" Add new Domain to Database """
self.collection.insert_one(target)
def _update(self, domain, newsubdomains):
""" Update subdomains for a given domain """
for subdomain in newsubdomains: self.collection.update({"domain": domain}, {"$push": {"subdomains": subdomain}})
def _findOne(self, domain):
""" Retrun all subdomains for a given domain """
return self.collection.find_one({"domain": domain})
def _delete(self, domain):
""" Delete domains and subdomians for a given domain """
self.collection.find_one_and_delete({"domain": domain})