MST

星途 面试题库

面试题:MongoDB聚合框架匹配阶段的条件组合应用

假设有一个MongoDB集合,文档结构如下:{ 'name': '字符串', 'age': 数值, 'city': '字符串','scores': [数值数组] }。请编写一个聚合管道,使用匹配阶段筛选出年龄在25到35岁之间(包含25和35),且所在城市为'Beijing',并且scores数组中至少有一个分数大于80的文档。
36.8万 热度难度
数据库MongoDB

知识考点

AI 面试

面试题答案

一键面试
[
    {
        $match: {
            age: { $gte: 25, $lte: 35 },
            city: 'Beijing',
            scores: { $elemMatch: { $gt: 80 } }
        }
    }
]