【发布时间】:2017-05-01 00:36:48
【问题描述】:
如何使用 pymongo 更新 MongoDB 中创建的文档?
例如:我有一个数据集:
name weight amount
-------------------------
apple 2 3
banana 2 5
我想得到水果的重量:重量 * 数量
name weight amount total
-----------------------------------
apple 2 3 6
banana 2 5 10
如何更新游标文档????
myFile = [
{"name":"Appel", "weight":2, "amount":3}, {"name":"banana", "weight":2, "amount":5}
]
myCollection.insert_many(myFile)
fruits = myCollection.find()
for fruit in fruits:
total = fruit["weight"]*fruit["amount"]
????? What should I do now? ?????
【问题讨论】: