mydoc = mycollection_Users.find_one( {}, { "Username": 0})
this is the code I wrote to get the password from MongoDB, when I put 0 in the search value it will give me all the values except Usernames' value. but I get the value like this
{'_id': ObjectId('618bc65e33c87d5cfbdd5a28'), 'Password': 'example'}
how can I only keep what the actual password is and remove everything else, the product should be just "example" and nothing else
Any help will be great, thx
CodePudding user response:
First convert the value into string and slice the text to get the password or put it in a variable and write password['Password']
CodePudding user response:
Try this
mydoc = mycollection_Users.find_one( {}, { "Username": 0, '_id': 0}).get('Password')
CodePudding user response:
I was able to remove the id value by adding "'_id': 0" so the code now is
mydoc = mycollection_Users.find_one( {}, { "Username": 0, '_id': 0})
but I still want to remove the {'password': }
CodePudding user response:
convert the value into string and slice the text to get the password or put it in a variable and write password['Password']