rockMongo的一些基本查询

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',
)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值