现有如下格式的集合
"objectiveQuestions" : [{
"answer" : "A",
"index" : 2,
"isCorrect" : 1,
"subjectId" : 5967
}, {
"subjectId" : 5968,
"answer" : "A",
"isCorrect" : 0,
"index" : 3
}, ...]
现在要为每个在objectiveQuestions
元素添加score
字段, 并给初始值2
. 请问如何构造update
语句呢
加个
multi: true
http://docs.mongodb.org/manual/reference/method/db.collection.update/
kemas kini({},{"$setOnInsert":{'score': 2}}, True, True)