mongoDB 常用的条件操作符有
$lt 小于
$gt 大于
$lte 小于或等于
$gte 大于或等于
$ne 不等于
$in in 判断用于判断元素是否在数组里面
$nin not in 判断用于判断元素是不是不在数组里面
$or 或判断
> db.tianyc02.find()
{ "_id" : ObjectId("50ea6eba12729d90ce6e3423"), "name" : "xttt", "age" : 111 }
{ "_id" : ObjectId("50ea6eba12729d90ce6e3424"), "name" : "xttt", "age" : 222 }
{ "_id" : ObjectId("50ea6b6f12729d90ce6e341b"), "name" : "xtt", "age" : 11 }
{ "_id" : ObjectId("50ea6b7312729d90ce6e341c"), "name" : "xtt", "age" : 22 }
> db.tianyc02.find({age:{$lt:100}})
{ "_id" : ObjectId("50ea6b6f12729d90ce6e341b"), "name" : "xtt", "age" : 11 }
{ "_id" : ObjectId("50ea6b7312729d90ce6e341c"), "name" : "xtt", "age" : 22 }
> db.tianyc02.find({age:{$lt:100,$gt:20}})
{ "_id" : ObjectId("50ea6b7312729d90ce6e341c"), "name" : "xtt", "age" : 22 }
> db.tianyc02.find({age:{$ne:11}})
{ "_id" : ObjectId("50ea6eba12729d90ce6e3423"), "name" : "xttt", "age" : 111 }
{ "_id" : ObjectId("50ea6eba12729d90ce6e3424"), "name" : "xttt", "age" : 222 }
{ "_id" : ObjectId("50ea6b7312729d90ce6e341c"), "name" : "xtt", "age" : 22 }
2.2 $in & $nin
> db.tianyc02.find()
{ "_id" : ObjectId("50ea6eba12729d90ce6e3423"), "name" : "xttt", "age" : 111 }
{ "_id" : ObjectId("50ea6eba12729d90ce6e3424"), "name" : "xttt", "age" : 222 }
{ "_id" : ObjectId("50ea6b6f12729d90ce6e341b"), "name" : "xtt", "age" : 11 }
{ "_id" : ObjectId("50ea6b7312729d90ce6e341c"), "name" : "xtt", "age" : 22 }
> db.tianyc02.find({age:{$in:[11,22]}})
{ "_id" : ObjectId("50ea6b6f12729d90ce6e341b"), "name" : "xtt", "age" : 11 }
{ "_id" : ObjectId("50ea6b7312729d90ce6e341c"), "name" : "xtt", "age" : 22 }
> db.tianyc02.find({age:{$nin:[11,22]}})
{ "_id" : ObjectId("50ea6eba12729d90ce6e3423"), "name" : "xttt", "age" : 111 }
{ "_id" : ObjectId("50ea6eba12729d90ce6e3424"), "name" : "xttt", "age" : 222 }
2.3 $or
> db.tianyc02.find({$or:[{age:11},{age:22}]})
{ "_id" : ObjectId("50ea6b6f12729d90ce6e341b"), "name" : "xtt", "age" : 11 }
{ "_id" : ObjectId("50ea6b7312729d90ce6e341c"), "name" : "xtt", "age" : 22 }
> db.tianyc02.find({$or:[{age:11},{name:'xttt'}]})
{ "_id" : ObjectId("50ea6eba12729d90ce6e3423"), "name" : "xttt", "age" : 111 }
{ "_id" : ObjectId("50ea6eba12729d90ce6e3424"), "name" : "xttt", "age" : 222 }
{ "_id" : ObjectId("50ea6b6f12729d90ce6e341b"), "name" : "xtt", "age" : 11 }

转载于:https://www.cnblogs.com/SunshineLittleCat/p/8280101.html

mongoDB条件操作符相关推荐

  1. MongoDB 条件操作符 gt、gte、lt、lte

    文章目录 MongoDB 条件操作符 MongoDB (>) 大于操作符 - $gt MongoDB(>=)大于等于操作符 - $gte MongoDB (<) 小于操作符 - $l ...

  2. MongoDB 条件操作符

    描述 条件操作符用于比较两个表达式并从mongoDB集合中获取数据. 在本章节中,我们将讨论如何在MongoDB中使用条件操作符. MongoDB中条件操作符有: (>) 大于 - $gt (& ...

  3. java rx.observable_Rxjava2 Observable的条件操作符详解及实例

    简要: 需求了解: 在使用 Rxjava 开发中,经常有一些各种条件的操作 ,如比较两个 Observable 谁先发射了数据.跳过指定条件的 Observable 等一系列的条件操作需求,那么很幸运 ...

  4. JavaScript运算符(二)相等、全等、赋值、关系操作符、条件操作符(即三元表达式)

    JavaScript运算符 相等操作符 相等操作符再JavaScript中主要用于判断等号两边的内容是否相等,使用'=='来表示. null和undefined可以相等,(null==undefine ...

  5. c++ 操作符大全-算术操作符、关系操作符、逻辑操作符、位操作符、自增自减操作符、赋值操作符、条件操作符、逗号操作符、操作符优先级

    文章目录 操作符 1.算术操作符 2.关系操作符 3.逻辑操作符 4.位操作符 5.自增自减操作符 6.赋值操作符 7.条件操作符 8.逗号操作符 9.操作符优先级 操作符 计算机程序可以看作一串运算 ...

  6. 【C++零碎】条件操作符(表达式)—问号(?)

    语法格式 (条件表达式)?(条件为真时的表达式):(条件为假时的表达式) 作用 (暂时没看懂, 看看例子应该就懂了) "--?--:--"称为条件操作符,它的运算优先级比逻辑或还低 ...

  7. mongodb更新操作符$min,$max

    mycode db.person.deleteOne({name:'lnj'}) db.person.insertOne({name:'zs',age:18}) //$min是用min指定的值和原来的 ...

  8. mongodb更新操作符$unset

    mycode db.person.find() //这里要删除ls的score字段,随便给一个值即可 db.person.update({'name':'ls'},{$unset:{'score':' ...

  9. mongodb数组操作符

    数组操作符 /* $all : 匹配数组中包含所有指定查询值的文档 {<field>: {$all: [<value1>, <value2>, ...]}} $el ...

最新文章

  1. Genome-scale de novo assembly using ALGA 使用ALGA进行 基因组规模的从头组装
  2. C++ ACM解题
  3. IIS 支持 php
  4. springboot entity date_SpringBoot+JWT实战(附源码)
  5. (转)求单链表是否有环,环入口和环长
  6. 卷积神经网络中feature map的含义
  7. 帆软部署到windows环境绝对路径及网络报表目录写法
  8. 最简单AS5048a模块鉴别和读取数据
  9. 优派 ELITE XG320Q、XG320U / UG 评测
  10. 各个CPU品牌介绍及散片和盒装CPU区别方法简介
  11. 直播带货行业如何入局?先了解一下直播商城源码吧
  12. Js逆向教程19-websocket介绍
  13. CTSCAPIO 2017游记
  14. JavaScript5:常用DOM操作
  15. jQuery属性操作以及一些实用方法
  16. HyperMesh Notes
  17. 计算机网络第四章答案
  18. CSS # 通过CSS使图片颜色反转
  19. 恺撒密码 python
  20. PNAS:婴儿早期的大脑功能灵活性

热门文章

  1. css input[type=file] 样式美化,input上传按钮美化
  2. 画一个皮卡丘项目小结(4)
  3. 个性化推荐系统(一)---今日头条等的内容划分、分类
  4. UI自动化录制工具----UI Recorder
  5. lambda expressions are not supported at this language level
  6. 全球主要城市经纬度api
  7. cogs luogu 珠心算测试【noip2014 普及组】
  8. BootStrap学习笔记,优缺点总结
  9. windows下eclipse连接hadoop
  10. java调用存储过程