加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > 学习资料

mongodb中比较级查询条件:($lt $lte $gt $gte)(大于、小于...

时间:2021-03-21 21:38:12  来源:  作者:
查询表中学生年级大于20,如下:

db.getCollection('student').find({'age':{'$gt':'20'}})



$lt    <   (less  than )

$lte    <=  (less than  or equal to )

$gt   >    (greater  than )

$gte   >=    (greater  than or   equal to)
 

本帖隐藏的内容

  1. $filter["gametime"] = ['$lte' => (int)$tendToday,'$gte' => (int)$zendToday];
复制代码



$ne  != (not equal to)不等于  {'age': {'$ne': 20}}

$in  在范围内  {'age': {'$in': [20, 23]}}   注意用list

$nin  (not in)  不在范围内{'age': {'$nin': [20, 23]}} 注意用list

$regex (正则匹配) db.collection.find({'name': {'$regex': '^M.*'}})  匹配以M开头的名字

$exists      属性是否存在       {'name': {'$exists': True}}     查找name属性存在

$type     类型判断        {'age': {'$type': 'int'}}       age的类型为int

$text      文本查询      {'$text': {'$search': 'Mike'}}     text类型的属性中包含Mike字符串

$or  查找多种条件   ({'$or':[{'name':'chen'},{'name':'wang'}]})
$where 查询两个键的值是否相等 db.test.find({"$where": "this.fields1 == this.fields2"}).limit(10);

$exists 键是否存在   {finaGoalLine:{'$exists':true}}

$all  如果您希望找到一个包含这两个元素的数组     [ 'tags' => [ '$all' => [ 'red'  'blank' ]]]

$elemMatch   运算符在数组的元素上指定多个条件    'dim_cm'  => ['$elemMatch'  =>  [ '$gt'  =>  22,'$lt'  =>  30,],],
$size 运算符按元素数查询数组   [ 'tags' => [ '$size' => 3








组合使用方法如下:

db.user.find({"age":{"$gte":18,"$lte":25}})



对于日期的条件查询方法:

db.getCollection('news').find({'pub_date':{'$gte':'2017-07-11  11:0:0'}})



2) 不等于 $ne

例子:

db.taobao.find( { age: { $ne : 10} } );
php7 查询mongodb方法大全

本帖隐藏的内容

  1. $data.$s = array(
  2.     ">" => 1,
  3.     "<" => 2
  4. );
  5. $data.$s['>='] = 4;
  6.  
  7. print_r($data);
  8.  
  9. echo strpos("12,3",",");
  10.  
  11. $filter["season_id"] = 106;
  12. //$filter["array.8"] = 'cml123';
  13. print_r($filter);echo "<br><br>";
  14.  
  15. $dataing = array(
  16.     "projection" => array(
  17.         '_id' => 0,"s_lastid" => 1,'id' => 1
  18.     ),
  19.     'limit' => 1,       //显示条数
  20.     'sort' => ['id'=> -1], //排序-1是降序  1为升序
  21.     'skip' => 1         //跳过几条
  22. );
  23.  
  24. $options = $dataing;
  25. $querys = new MongoDB\Driver\Query($filter,$options);
  26. $cursors = $manager->executeQuery('football.football_Competition_season_matches', $querys);
  27. $schedule= mg_querys($cursors);
  28. print_r($schedule);
复制代码

查询中的 and or
  1. //and
  2. {key1:value1, key2:value2}
  3. [key1=>value1, key2=>value2]
  4. //or
复制代码

'sort' => ['id'=> -1] //排序-1是降序  1为升序



H0y华陈数据科技
H0y华陈数据科技
H0y华陈数据科技
H0y华陈数据科技
H0y华陈数据科技
 
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
实现php间隔一段时间执行一次某段代码
实现php间隔一段时间
相关文章
    无相关信息
栏目更新
栏目热门