• MongDB4.0-入门学习之运算符


    MongDB 4.0 入门学习之运算符

    基本语法:db.collection.find({<key>:{$symbol:<value>}})

    条件查询匹配运算符

    符号 描述 范例 js释义
    $eq 等于 {qty:{$eq:2}} or {qty:2} qty===2
    $gt 大于 {qty:{$gt:2}} qty>2
    $gte 大于或等于 {qty:{$gte:2}} qty>=2
    $lt 小于 {qty:{$lt:2}} qty<2
    $lte 小于或等于 {qty:{$lte:2}} qty<=2
    $ne 不等于 {qty:{$ne:2}} qty!=2
    $in 查询等于指定数组中任何值的数据 {qty:{$in:[5,2,3]}} qty===5 || qty===2 || qty===3
    $nin 查询不等于指定数组中任何值数据 {qty:{$nin:[5,2,3]}} qty!=5 || qty!=2 || qty!=3

    逻辑运算符

    • $and 逻辑且

      • 语法: {$and:[{<expression1>}, {<expression2>}, ... ,{<expressionN>}]}
      • 范例: {$and:[{qty:{$ne:2}},{"name":{$eq:"测试"}}]}
      • 范例js释义: qty!=2 && "name"==="测试"
    • $not 逻辑非

      • 语法: {<key>:{$not:{<operator-expression>}}}
      • 范例: {price:{$not:{$gt:1.99}}}
      • 范例js释义: !(price>1.99)
    • $nor 逻辑非或

      • 语法: {$nor:[{<expression1>}, {<expression2>}, ...,{<expressionN>}]}
      • 范例: {$nor:[{price:1.99}, {sale:true}]}
      • 范例js释义: !(price===1.99||sale===true)
    • $or 逻辑或

      • 语法: {$or:[{<expression1>}, {<expression2>}, ...,{<expressionN>}]}
      • 范例: {$or:[qty:{$lt:20}}, {price:10}]}
      • 范例js释义: qty<20 || price===10

    检测运算符

    • $exists 查询值是否存在

      • 语法: {<key>:{$exists:<boolean>}}
      • 范例: {qty:{$exists:true, $nin:[ 5, 15 ]}}
      • 范例js释义: qty && (qty!=5 || qty!=15)
    • $type 检测值的类型

      • 语法: {<key>:{$type:<BSON type>}}
      • 范例: {"zipCode":{$type:2}}} or {"zipCode":{$type:"string"}}}
      • 范例js释义: typeof "zipCode" === "string"
      • 数据类型请自行到官网文档查询 MongoDB Operator $type
  • 相关阅读:
    AtCoder Beginner Contest 169
    Codeforces Round #646 (Div. 2)
    Educational Codeforces Round 88 (Rated for Div. 2)
    Codeforces Round #645 (Div. 2)
    【uoj】【美团杯2020】平行四边形(原根)
    【uoj】【美团杯2020】半前缀计数(后缀自动机)
    Codeforces Round #644 (Div. 3)
    [COI2009] OTOCI
    [AHOI2005] 航线规划
    [P1390] 公约数的和
  • 原文地址:https://www.cnblogs.com/leona-d/p/11065947.html
Copyright © 2020-2023  润新知