维多利亚”, “3”:“ 撒哈拉 </跨度> 沙漠” ] } { “_id”:“45657865745”, “名字”:“谦虚”, “基本介绍”:“B.C.D。”, “地方很重要
这应该会让你知道如何做到这一点
import pymongo client = pymongo.MongoClient('yourHost', 30000) # adjust to your needs db = client.so coll = db.yourcollection # show initial data for doc in coll.find(): print(doc) # update data places_visited = [ "Palace of Dob", "Palace of Victoria", "Sahara Desert" ] coll.update({}, { "$set": { "Places Visited": places_visited } }, multi=True) # show updated data for doc in coll.find(): print(doc)
对于您的样本数据,应该提供与此类似的输出
daxaholic$ python3 main.py {'name': 'Bunty', 'Basic Intro': 'A.B.C.D.', '_id': '4564345343'} {'name': 'Humty', 'Basic Intro': 'B.C.D.', '_id': '45657865745'} {'name': 'Bunty', 'Places Visited': ['Palace of Dob', 'Palace of Victoria', 'Sahara Desert'], 'Basic Intro': 'A.B.C.D.', '_id': '4564345343'} {'name': 'Humty', 'Places Visited': ['Palace of Dob', 'Palace of Victoria', 'Sahara Desert'], 'Basic Intro': 'B.C.D.', '_id': '45657865745'}
有关详细信息,请参阅 文档 关于 update
update