0

Im trying to make a web app in Flask with Pymongo and a MongoDB Im getting that it cant find the attribute password in my db under users

elif request.method == 'POST':
    login_user = request.form['username']
    db_user = mongo.db.users.find({"username": "MattatMatt"})
    pw = db_user.password

I know im being an idiot, please help. This is the database:

username:"MattatMatt"
password:"..."

If you need anything else please ask. Thank you!!!

Matthew Casey
  • 145
  • 1
  • 3
  • 12

1 Answers1

1

find() returns a cursor. You likely want find_one() which returns a single record as a dict. As it's a dict and not an object, you will need to get the password using db_user['password'], e.g.

elif request.method == 'POST':
    login_user = request.form['username']
    db_user = mongo.db.users.find_one({"username": "MattatMatt"})
    pw = db_user['password']
Belly Buster
  • 8,224
  • 2
  • 7
  • 20