I'm slowly getting desperate about this. I am trying to get a very specific entry from a previously defined database. For this I have defined my database:
test = cluster["folder1"]["example"]
In this there are keys with a value, that looks something like this:
Now I want to use the find_one() or find() method to find this entry. There are more entries in the database.
I already managed to go over the collection with a loop and the entry is also displayed:
def get_key(guild, answer):
for x in test.find({}, {f"{answer}"}): # The searched "answer" is defined before by a command, not needed for this matter
print(x)
EDIT: Maybe I need to mention this: "answer" can also have a different value, for example "quantum" which is then maybe "assigned" to "This is quantum" or "finger" which is "assigned" to "This is a finger". Therefore, I can't use test.find_one({"test: "FAILUR"}) and need to find a way to find the value for the key "answer"
It will look like this:
{'_id': ObjectId('Removed')}
{'_id': ObjectId('Removed')}
{'_id': ObjectId('Removed'), 'test': 'FAILUR'} # I just need FAILUR
I would now like to display "FAILUR" and not always use a for loop. Is this therefore much easier and faster with the find_one() method?
Already I tried:
print(test.find_one({f"{answer}": f"{answer}"})) # Outputs None
print(test.find({}, {f"{answer}"})) # prints <pymongo.cursor.Cursor object at 0x7fc6d482XXX>
Additionally, I looked at the following posts, but just didn't get anywhere:
https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/ https://docs.mongodb.com/manual/reference/method/db.collection.findOne/
How to select a single field for all documents in a MongoDB collection?
How to read a specific key-value pair from mongodb collection
And much more. Thanks in advance!