• 概述
    • 选择符

    概述

    选择符

    选择符可以实现对查询的结果字段进行拆分、筛选等功能。在选择符中使用函数操作还能实现对结果的重写和转换等操作。

    支持的选择符如下:

    选择符描述示例
    $include选择或移除某个字段db.foo.bar.find( {}, { "a": { "$include": 1 } } )
    $default当字段不存在时返回默认值db.foo.bar.find( {}, { "a": { "$default": "myvalue" } } )
    $elemMatch返回数组内满足条件的元素的集合db.foo.bar.find( {}, { "a": { "$elemMatch": { "a": 1 } } } )
    $elemMatchOne返回数组内满足条件的第一个元素的集合db.foo.bar.find( {}, { "a": { "$elemMatchOne": { "a": 1 } } } )

    同时函数操作也可以作为选择符使用。