添加資料
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" }}