tp5+Mongodb查询时间段内的数据

29 篇文章 0 订阅
13 篇文章 0 订阅

添加数据

public function add(){
        $this->data = [
            [
                'cust_id'  =>  '001',
                'amount'   =>  100,
                'status'   =>  'A',
                'time'     =>   1500134400
            ],
            [
                'cust_id'  =>  '001',
                'amount'   =>  120,
                'status'   =>  'A',
                'time'     => 1502726400
            ],
            [
                'cust_id'  =>  '002',
                'amount'   =>  10,
                'status'   =>  'B',
                'time'     => 1504281600
            ],
        ];
        $res = Db::table('document')->insertAll($this->data);
        if($res){
            echo "success";
        }else{
            echo "error";
        }
    }

结果

array(3) {
  [0] => array(5) {
    ["_id"] => object(MongoDB\BSON\ObjectId)#12 (1) {
      ["oid"] => string(24) "5a51fffb83869e5bf002656b"
    }
    ["cust_id"] => string(3) "001"
    ["amount"] => int(100)
    ["status"] => string(1) "A"
    ["time"] => int(1500134400)
  }
  [1] => array(5) {
    ["_id"] => object(MongoDB\BSON\ObjectId)#13 (1) {
      ["oid"] => string(24) "5a51fffb83869e5bf002656c"
    }
    ["cust_id"] => string(3) "001"
    ["amount"] => int(120)
    ["status"] => string(1) "A"
    ["time"] => int(1502726400)
  }
  [2] => array(5) {
    ["_id"] => object(MongoDB\BSON\ObjectId)#14 (1) {
      ["oid"] => string(24) "5a51fffb83869e5bf002656d"
    }
    ["cust_id"] => string(3) "002"
    ["amount"] => int(10)
    ["status"] => string(1) "B"
    ["time"] => int(1504281600)
  }
}

根据时间段查询

public function select_by_time(){
        // $map['time'] = ['between','1500134399','1502726401'];
        $map['time'] = array('between',['1500134399','1502726401']);
        $res = Db::table('document')->where($map)->select();
        dump($res);
    }

结果

array(2) {
  [0] => array(5) {
    ["_id"] => object(MongoDB\BSON\ObjectId)#12 (1) {
      ["oid"] => string(24) "5a52011083869e4b674156fa"
    }
    ["cust_id"] => string(3) "001"
    ["amount"] => int(100)
    ["status"] => string(1) "A"
    ["time"] => string(10) "1500134400"
  }
  [1] => array(5) {
    ["_id"] => object(MongoDB\BSON\ObjectId)#13 (1) {
      ["oid"] => string(24) "5a52011083869e4b674156fb"
    }
    ["cust_id"] => string(3) "001"
    ["amount"] => int(120)
    ["status"] => string(1) "A"
    ["time"] => string(10) "1502726400"
  }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值