面试题答案
一键面试假设使用的是MongoDB数据库,以下是查询语句:
db.students.find({
age: {
$not: {
$gte: 18,
$lte: 22
}
}
});
解释:
db.students.find()
是MongoDB中用于查询集合students
的方法。age
是文档中的年龄字段。$not
操作符用于对条件取反。$gte
表示大于等于,$lte
表示小于等于,这里组合条件表示年龄不在18(含)到22(含)之间。