I have the document below. I would like to get the topic field if the password matches.
email: "info@info.com"
first_name: "james"
password: Binary('HcM0Js5Pqh8oGZxLSNuMJNgb5l1WUCn5NRhB/L4juIY=')
surname:"mcarthy" topic: "journalism"
I am using below code to check if the key exists.
user = user_in_db.find_one({'password': key})
if user is None:
How can i retrieve the topic field if the user does exist?
That is very simple. As per this official tutorial , the return of find_one
is a dictionary, hence you could do something like:
user = user_in_db.find_one({'password': key})
if user: # check if user exists
topic = user['topic']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.