一、更新一层嵌套数组
首先执行MongoDB原生语句脚本在user集合中产生一些样本数据,如下所示:
db.user.insert({"_id":1,"title":"爱情公寓3","students":[{"student_id":1001,"student_name":"林宛瑜"},{"student_id":1002,"student_name":"陆展博"}]});
db.user.insert({"_id":2,"title":"爱情公寓4","students":[{"student_id":2001,"student_name":"吕子乔"},{"student_id":2002,"student_name":"张伟"}]});
如果想将“吕子乔”修改为“曾小贤”,则可以执行下述脚本进行数据更新:
db.user.updateMany(
{'students.stud