post = {
'username': username,
'password': password,
'exp': 0,
'level': 1
}
这是我到目前为止。如果我做这样的事情:
post['exp'] = 10
这种变化不是永久性的。我查了一下,有一个更新功能,但它们似乎都涉及 ids 和 set,我不太熟悉。有人可以就更新帖子中的值给我建议吗?
将 find_one_and_update 函数与您的 pymongo 连接一起使用:
# Assuming your connecting to a local database
conn = pymongo.MongoClient('mongodb://localhost:27017')
collection = conn['database_name']['collection_name']
# Lets say you use a username to find your document
collection.find_one_and_update(
{'username': 'yasong'}, {'$set': {'exp': 10}}
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句