forked from smarthaut/Daemon_AutoFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongo_db.py
More file actions
31 lines (27 loc) · 815 Bytes
/
Copy pathmongo_db.py
File metadata and controls
31 lines (27 loc) · 815 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/4/13 13:11
# @Author : huanghe
# @Site :
# @File : mongo_db.py
# @Software: PyCharm
import pymongo
from src.utils.config import Config
class DB:
def __init__(self):
cf = Config().get('mongodb')
self.host = cf.get('host')
self.port = cf.get('port')
self.user = cf.get('user')
self.password = cf.get('password')
try:
self.client = pymongo.MongoClient(self.host, port=int(self.port))
except:
print('数据库连接失败')
def getConnection(self, table_name, connection_name):
db = self.client.get_database(table_name)
svod = db.get_collection(connection_name)
return svod
if __name__ =='__main__':
db =DB()
print(db.host)