MongoDB更新数组中字母的所有迭代

时间:2017-05-31 14:36:14

标签: mongodb

大家好我有以下例子:

{
"_id" : ObjectId("591dea6af63ae97d813d3865"),
"borough" : "Queens",
"cuisine" : "American ",
"grades" : [ "A", "A", "B", "B" ],
"name" : "Yummy Fried Chicken And Pizza",
"restaurant_id" : "50000605"
}

我想更改S等级的所有A等级,我尝试了这个查询:

db.restaurants.update({},{$set: {grades : "S"}})

它似乎无法工作,任何想法如何做到这一点?

1 个答案:

答案 0 :(得分:0)

答案是:

db.restaurants.update({},{$set: {grades.$ : "S"}})