更新文档

  1. import pymongo
  2.  
  3. myclient = pymongo.MongoClient("mongodb://localhost:27017/")
  4. mydb = myclient["mydatabase"]
  5. mycol = mydb["customers"]
  6.  
  7. myquery = { "address": "Valley 345" }
  8. newvalues = { "$set": { "address": "Canyon 123" } }
  9.  
  10. mycol.update_one(myquery, newvalues)
  11.  
  12. #print "customers" after the update:
  13. for x in mycol.find():
  14. print(x)