$include

语法

  1. { <字段名1>: { $include: <0|非0> }, <字段名2>: { $include: <0|非0>, ... } }

说明

$include 可以指定选择或移除某个字段。

作用
非0选择字段
0移除字段

示例

在集合 sample.employee 插入1条记录:

  1. > db.sample.employee.insert( { "_id": 1, "class": 1, "students": [ { "name": "ZhangSan", "age": 18 }, { "name": "LiSi", "age": 19 }, { "name": "WangErmazi", "age": 18 } ] } )

SequoiaDB shell 运行如下:

  • 查询集合 sample.employee,指定选择“students”字段:

    1. > db.sample.employee.find( {}, { "students": { "$include": 1 } } )
    2. {
    3. "students": [
    4. {
    5. "name": "ZhangSan",
    6. "age": 18
    7. },
    8. {
    9. "name": "LiSi",
    10. "age": 19
    11. },
    12. {
    13. "name": "WangErmazi",
    14. "age": 18
    15. }
    16. ]
    17. }
    18. Return 1 row(s).
  • 查询集合 sample.employee,指定移除“students”字段:

    1. > db.sample.employee.find( {}, { "students": { "$include": 0 } } )
    2. {
    3. "_id": 1,
    4. "class": 1
    5. }