$subtract

语法

  1. { <字段名>: { $subtract: <值> } }

说明

返回字段值减去某个数值的结果。原始值为数组类型时对每个数组元素执行该操作,非数字类型返回 null

示例

在集合 foo.bar 插入1条记录:

  1. > db.foo.bar.insert( { "a": 40 } )

SequoiaDB shell 运行如下:

  • 作为选择符使用,返回字段“a”减去10的结果:
  1. > db.foo.bar.find( {}, { "a": { "$subtract": 10 } } )
  2. {
  3. "_id": {
  4. "$oid": "58257c0dec5c9b3b7e000003"
  5. },
  6. "a": 30
  7. }
  8. Return 1 row(s).
  • 与匹配符配合使用,匹配字段“a”减去10之差为30的记录:
  1. > db.foo.bar.find( { "a": { "$subtract": 10, "$et": 30 } } )
  2. {
  3. "_id": {
  4. "$oid": "58257c0dec5c9b3b7e000003"
  5. },
  6. "a": 40
  7. }
  8. Return 1 row(s).