qrcode_be/lib/db.py
2020-12-02 22:48:54 +08:00

33 lines
735 B
Python

from pymongo import MongoClient
from bson import ObjectId, json_util
# 获取数据集
def col(arg: str = None):
conn = MongoClient('mongodb://qrcode:mR6rN4pI0rU6@mongo:27017/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