主页
Python
Python MongoDB 更新方法
demo_mongodb_update_many
运行 ❯
×
更改方向
保存代码
更改主题
import pymongo myclient = pymongo.MongoClient("mongodb://localhost:27017/") mydb = myclient["mydatabase"] mycol = mydb["customers"] myquery = { "address": { "$regex": "^S" } } newvalues = { "$set": { "name": "Minnie" } } x = mycol.update_many(myquery, newvalues) print(x.modified_count, "documents updated.")
C:\Users\My Name>python demo_mongodb_update_many.py
2 documents updated.