{ "apple_pie" : { "ingredients" : [ "flour", "orange", "butter", "sugar" ] } }
db.recipes.update( {"apple_pie.ingredients": "orange"}, { "$set": {"apple_pie.ingredients.$": "apple"} } )
Once we have selected an element on the query side of the update, we can refer to it with $. So, this update operation means: "select the array element named orange, and set it to apple".
参照:
http://www.developingandstuff.com/2013/12/modify-element-of-array-in-mongodb.html