Python --链接Mongodb

 

 

# -*- coding: UTF-8 -*-
from pymongo import MongoClient


# 数据库连接
class MongoDB(object):
    def __init__(self, host='localhost', port=27017, database='xunfeng', username='', password=''):
        self.host = host
        self.port = port
        self.database = database
        self.conn = MongoClient(self.host, self.port)
        self.coll = self.conn[self.database]
        self.coll.authenticate(username, password)

 

posted @ 2017-03-27 16:17  八月的男人  阅读(554)  评论(0编辑  收藏  举报