#!/usr/bin/env python
# -*- coding:utf-8 -*-
from pymongo import MongoClient
import pycomm

# settings = {
#     "ip": '192.168.2.200',  # ip
#     "port": 27017,  # 端口
#     "db_name": "kaiyou",  # 数据库名字
#     "set_name": "test_set",  # 集合名字
#     "user": '',
#     'pwd': '',
# }


class DBMongo(object):

    def __init__(self, host, dbname, user, pwd, port):
        try:
            uri = 'mongodb://' + user + ':' + pwd + '@' + host + ':' + port + '/' + dbname
            print(uri)
            self.conn = MongoClient(uri)
            self.db = self.conn[dbname]

        except Exception as e:
            pycomm.toLog(e)

    # 选定数据集
    def changeSet(self,setname):
        return self.db[setname]
        



# def main():
    # mongo = MongoDataBase('192.168.0.250', 'kaiyou','kaiyou', 'ky123456', '27017').changeSet('prize')
    # pycomm.toLog('no cmd')
    # dic = {"name": "zhangsan", "age": 18}

    # mongo.insert(dic)
    # pycomm.toLog(mongo.find_one({"name":"zhangsan"}))
#     return
    # dic = {"name":"zhangsan", "age":18}
    # mongo = MyMongoDB()
    # mongo.insert(dic)
    # mongo.dbfind({"name":"zhangsan"})

    # mongo.update({"name":"zhangsan"}, {"$set":{"age":"25"}})
    # mongo.dbfind({"name":"zhangsan"})

    # mongo.delete({"name":"zhangsan"})
    # mongo.dbfind({"name":"zhangsan"})


# if __name__ == "__main__":
#     main()
