Ask coding questions

← Back to all posts
Invalid Syntax MongoDB
meziosaur (0)

userbank.update_one({(str(username))},{$set: {"coin0":300}})

In that code above I get a 'invalid syntax error' at the '$' symbol but it's what MongoDB uses.

I have pymongo and dnspython packages installed too

any idea on why this happens?

Answered by InvisibleOne (3206) [earned 5 cycles]
View Answer
Comments
hotnewtop
InvisibleOne (3206)

I always specify which field I am checking for, not just put the username, I don't know your exact code but I'm guessing you need to do something like this

t = userbank.update_one({'username' : str(username)}, {'$set' : {'coin0' : 300}})