仅当用户输入存在于 mongodb 中时才通过获取用户输入来更新字段
Update a field by taking user input only if it exists in mongodb
我有一个名称、地址、电子邮件的集合,所有集合的 IsActive 默认为 true。
我想通过接受用户输入将 IsActive 更改为 false。
用户将提供电子邮件地址,如果它存在于集合中,则该电子邮件地址的 IsActive 应更改为 false,如果它不存在,则输出应作为电子邮件地址不存在。集合存储在名为 user.
的集合文件中
{
"_id" : ObjectId("5e155d4df9f62e4709a814b8"),
"name" : "oihjoi",
"Address" : "pojpjo",
"Email" : "oiwjxoni@psdcmpd.com",
"IsActive" : "True"
}
def terminating_user_active():
result = user.update_one(
{"Email": input("Enter email address to be terminated : ")}, {"$set": {"IsActive": False}})
if result.modified_count == 0:
print("\n Entered email address does not exist in collection \n")
else:
print("\n Entered email address active is terminated \n")
terminating_user_active()
我有一个名称、地址、电子邮件的集合,所有集合的 IsActive 默认为 true。 我想通过接受用户输入将 IsActive 更改为 false。
用户将提供电子邮件地址,如果它存在于集合中,则该电子邮件地址的 IsActive 应更改为 false,如果它不存在,则输出应作为电子邮件地址不存在。集合存储在名为 user.
的集合文件中{
"_id" : ObjectId("5e155d4df9f62e4709a814b8"),
"name" : "oihjoi",
"Address" : "pojpjo",
"Email" : "oiwjxoni@psdcmpd.com",
"IsActive" : "True"
}
def terminating_user_active():
result = user.update_one(
{"Email": input("Enter email address to be terminated : ")}, {"$set": {"IsActive": False}})
if result.modified_count == 0:
print("\n Entered email address does not exist in collection \n")
else:
print("\n Entered email address active is terminated \n")
terminating_user_active()