久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      解析TP框架下mongo的基礎(chǔ)操作及其注意點(diǎn)

      下面thinkphp框架教程欄目將給大家介紹關(guān)于thinkphp下的mongo的操作,希望對(duì)需要的朋友有所幫助!

      解析TP框架下mongo的基礎(chǔ)操作及其注意點(diǎn)

      1.多個(gè)條件語(yǔ)句,網(wǎng)上很多只是一個(gè)大于或者一個(gè)小于,沒(méi)有2個(gè)合并的,如大于2并且小于4的

      $where['_string'] = 'this.b > 2 & this.b<4';

      2.group

      mysql: $res = $model->where(['sTaskId'=>['$in'=>$task_array]])->group('a')->field('a,sum(a)')->select();  mongodb: $key = ['a'=>1]; //groupby的字段 $init = ['num'=>0];//統(tǒng)計(jì)的初始值 $option = array( 'table' => 'course’, // 表名 'condition’=>['sTaskId'=>['$in'=>$task_array]], //group中過(guò)濾條件 ); //必須要帶option $reduce = "function(obj, prev){prev.num = prev.num+obj.a}"; $model = new TestModel(); $res = $model->group($key, $init, $reduce, $option); 這里講一下tp的mongo擴(kuò)展是有問(wèn)題的,在group里調(diào)用where會(huì)無(wú)效,具體解決方案是要在mongo.class.php文件 a.把$query改為如下: $query  =  $this->parseWhere(isset($options['condition'])?$options['condition']:array()); 當(dāng)然$this->queryStr  也要改的 b.把$group改為: $group = $this->_collection->group($keys,$initial,$reduce,$query);

      3.如果你要用model模型去查詢(xún),并且你的主配置是mysql,那就需要先在配置文件配置

      'mongo' => [ DB_TYPE =>  mongo             DB_HOST => localhost    DB_NAME => test DB_PORT =>  40000 DB_PREFIX =>''  DB_USER => '' DB_PWD => '' ],

      然后在model文件里配置,
      a.protected $trueTableName = '表名';
      b.protected $connection = '驅(qū)動(dòng)名,這里是mongo';
      c.該model繼承MongoModel

      4.批量更新

      mysql里只要$res = $model->save(['a'=>1']); mongo的話(huà)需要寫(xiě)成$res = $model->where([])->save(['a'=>1]);

      5.mongo注意點(diǎn):

      mongo對(duì)于數(shù)據(jù)類(lèi)型的控制比較嚴(yán)格,如果你存?zhèn)€int的1,用'1'去查是查不到的!

      推薦:《最新的10個(gè)thinkphp視頻教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)