Rockmongo 查询条件总结

来源:互联网 发布:男士整容知乎 编辑:程序博客网 时间:2024/06/02 19:42

Json 格式查询


基本查询

{
"Deleted": "1"                
}


并列条件

{
"xid": 560870,
"type": "video"
}


查询带有集合的数据

{
    "Parameter.centerCityId": "6666"            
}


不等于

{
    "Deleted": {$ne:"1"}                 
}


说明:
$gt   >
$gte  >=
$lt   <
$lte  <=
$ne   !=
$in : in
$nin: not in
$all: all
$not: 反匹配


判断字段是否存在

{
    "Deleted": {$exists: true}             
}


为空数据处理

{
    "Deleted": null            
}


IN 包含

{

 "Deleted":{$in: [7,8]}
}



查询数组


对于{name: 'David', age: 26, favorite_number: [ 6, 7, 9 ] }记录

{

favorite_number:{$size:3}                
}


匹配db.users.find({favorite_number: {$size: 3}});

不匹配db.users.find({favorite_number: {$size: 2}});




正则 不以T开头的

name: {$not: /^T.*/}


Array 格式查询


1.简单查询
//xid=560870 and type=video
{
"xid": 560870,
"type": "video"
}

//查询数组中的数据
array(
"fruit.name"=>'aa'
)
返回如:
array (
  'fruit' =>
  array (
    'name' => 'aa',
    'age' => '34',
  ),
  'name' => 'caihuafeng',
)


2.模糊查询
//content like %爱%
array(
"content"=>new MongoRegex("/爱/i")
)

//查询以"爱"开头并且以"爱"结尾的数据
array(
"content"=>new MongoRegex("/^爱$/i")
)

3.大于、小于、不等于查询
//uid>=561484
array(
"uid"=>array('$gte'=>561484)
)

//uid>=0 and uid<=561484
array(
"uid"=>array('$gte'=>0,'$lte'=>561484)
)

//uid in (561484,0)
array(
"uid"=>array('$in'=>array(561484,0))
)

说明:
$gt   >
$gte  >=
$lt   <
$lte  <=
$ne   !=
$in : in
$nin: not in
$all: all
$not: 反匹配

4.查询指定字段
//查询存在uid字段的数据
array(
"uid"=>array('$exists'=>true)
)

//查询不存在uid字段的数据
array(
"uid"=>array('$exists'=>false)
)

5.查询字段类型
//查询content字段为字符型的数据
array(
"content"=>array('$type'=>2)
)
2   字符型
16  整型

6.查询数组指定的长度
//查询fruit大小为2的数据
array(
"fruit"=>array('$size'=>2)
)
返回如下:
array (
  '_id' => new MongoId("4e411abf7c1883973c0e2114"),
  'fruit' =>
      array (
        '0' => 'aa',
        '1' => 'bb',
      ),
  'name' => 'caihuafeng',
)






原创粉丝点击