Hello!
I’ve been trying to get my query to work but it always fails, so I’m guessing I have a syntax error of some sort. I basically want to check if a specific userid exists, so in my case my query should return True, but it returns false. Can anyone help?
Hello @Lily_B, welcome to the MongoDB Community forum!
The following query will work in PyMongo:
for doc in mydb.mycollection.find( { "buttons.userid": 67890 }, limit = 1 ):
print(doc)
It will print the first matching document, as you have specified the limit = 1 option. The find method returns a cursor, which will be empty if there is no match.
Since you are trying to check if there are any documents exist, you can use the following query (instead of); it prints the count of matching documents.