1.多個條件語句,網上不少只是一個大於或者一個小於,沒有2個合併的,如大於2而且小於4的php
$where['_string'] = 'this.b > 2 & this.b<4';
2.groupmysql
mysql: $res = $model->where(['sTaskId'=>['$in'=>$task_array]])->group('a')->field('a,sum(a)')->select(); mongodb: $key = ['a'=>1]; //groupby的字段 $init = ['num'=>0];//統計的初始值 $option = array( 'table' => 'course’, // 表名 'condition’=>['sTaskId'=>['$in'=>$task_array]], //group中過濾條件 ); //必需要帶option $reduce = "function(obj, prev){prev.num = prev.num+obj.a}"; $model = new TestModel(); $res = $model->group($key, $init, $reduce, $option); 這裏講一下tp的mongo擴展是有問題的,在group裏調用where會無效,具體解決方案是要在mongo.class.php文件 a.把$query改成以下: $query = $this->parseWhere(isset($options['condition'])?$options['condition']:array()); 固然$this->queryStr 也要改的 b.把$group改成: $group = $this->_collection->group($keys,$initial,$reduce,$query);
3.若是你要用model模型去查詢,而且你的主配置是mysql,那就須要先在配置文件配置sql
'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 = '驅動名,這裏是mongo';
c.該model繼承MongoModelmongodb
4.批量更新this
mysql裏只要$res = $model->save(['a'=>1']); mongo的話須要寫成$res = $model->where([])->save(['a'=>1]);
5.mongo注意點:code
mongo對於數據類型的控制比較嚴格,若是你存個int的1,用'1'去查是查不到的!