I am using python code for updating multiple elements in an array that matches a query. Here is my document structure:
doc: {
"userId":327238,
"assessmentId":115513,
"institutionId":1632,
"subjects":[
{"Id":238,"Included":false,"Rank":1},
{"Id":239,"Included":true,"Rank":4},
{"Id":240,"Included":false,"Rank":1},
{"Id":241,"Included":true,"Rank":10}
]
}
I would like to set 'Rank':0 only for array elements with 'Included':false. I have tried the below code but it sets 'Rank':0 for all the array elements.
query = {"assessmentId":115513, "institutionId":1632, "subjects":{"$elemMatch":{"Included":false}}}
update = {"$set":{"subjects.$[].Rank":0}}
db.test.update_many(query, update)
Any help would be appreciated . Thank you
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…