更新数组中的一个值

{
 students: [
              { name: "john", school: 102, age: 4 },
              { name: "jess", school: 102, age: 11 },
              { name: "jeff", school: 108, age: 7 }
           ]
}
{
 students: [
              { name: "ajax", school: 100, age: 7 },
              { name: "achilles", school: 100, age: 8 },
           ]
}
{
 students: [
              { name: "bob", school: 100, age: 7 },
              { name: "manuel", school: 100, age: 8 },
           ]
}

更新7age=7的 school 为101
db.students.update({"students.age":7},{$set: {"students.$.school":101}},true,true)
 

你可能感兴趣的:(数组)