我是python的初学者。我正在尝试连接到数据库并匹配用户输入的值。
if staff==<user entered value>and paper==<user entered value>:
test=db.staff.find({"staff":<user entered value>,"paper":<user entered value>})
print(test.get('staff'))
print(test.get('paper'))如果test没有值,当数据库没有返回值时,我会得到错误
发布于 2015-08-05 15:42:33
你应该使用来检查你的查询是否返回任何result.
if staff==and paper==:db.staff.find= db.staff.find({"staff":,"paper":}) if(test.count()):对于测试中的单据:打印(测试‘staff’)打印
如果staff和paper在集合中是唯一的,请使用方法。
if staff==<user entered value>and paper==<user entered value>:
test = db.staff.find_one({"staff":<user entered value>,"paper":<user entered value>})
if(test):
print(test['staff'])
print(test['paper'])https://stackoverflow.com/questions/31826066
复制相似问题