MST

星途 面试题库

面试题:MongoDB中如何使用条件操作符更新文档中的特定字段

假设存在一个集合students,其中文档结构为{name: '张三', age: 20, scores: {math: 85, english: 90}},现在要将年龄大于18岁且数学成绩大于80分的学生的英语成绩提高5分,使用MongoDB的条件操作符实现该更新操作,写出对应的更新语句。
47.2万 热度难度
数据库MongoDB

知识考点

AI 面试

面试题答案

一键面试
db.students.updateMany(
    { age: { $gt: 18 }, "scores.math": { $gt: 80 } },
    { $inc: { "scores.english": 5 } }
);