qrcode_be/lib/db.py
2021-08-02 19:21:38 +08:00

33 lines
741 B
Python

from pymongo import MongoClient
from bson import ObjectId, json_util
# 获取数据集
def col(arg: str = None):
conn = MongoClient('mongodb://qrcode:jh6uuRsywr8dg6@10.99.0.4:27001/qrcode')
return conn.qrcode[arg]
# 查找该用户所有信息
def findUser(openid):
arr = []
for i in col('code').find({'openId': openid}):
arr.append(i)
return json_util.dumps(arr)
# 删除该二维码
def delCode(id):
try:
col('code').remove({"_id" : ObjectId(id)})
except Exception as e:
# id不合法
return False
return {'errcode': 200, 'errmsg': 'ok'}
# 用户上传进入主表
def insertCode(data):
try:
res = col('code').insert_one(data)
except Exception as e:
# 失败
return False
return True