|
|
@ -5,7 +5,7 @@ |
|
|
|
* @license http://www.yiiframework.com/license/ |
|
|
|
* @license http://www.yiiframework.com/license/ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
namespace yii\mongo; |
|
|
|
namespace yii\mongodb; |
|
|
|
|
|
|
|
|
|
|
|
use yii\base\Component; |
|
|
|
use yii\base\Component; |
|
|
|
use yii\db\QueryInterface; |
|
|
|
use yii\db\QueryInterface; |
|
|
@ -60,7 +60,7 @@ class Query extends Component implements QueryInterface |
|
|
|
public function getCollection($db = null) |
|
|
|
public function getCollection($db = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($db === null) { |
|
|
|
if ($db === null) { |
|
|
|
$db = Yii::$app->getComponent('mongo'); |
|
|
|
$db = Yii::$app->getComponent('mongodb'); |
|
|
|
} |
|
|
|
} |
|
|
|
return $db->getCollection($this->from); |
|
|
|
return $db->getCollection($this->from); |
|
|
|
} |
|
|
|
} |
|
|
@ -180,7 +180,7 @@ class Query extends Component implements QueryInterface |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Executes the query and returns all results as an array. |
|
|
|
* Executes the query and returns all results as an array. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* If this parameter is not given, the `mongo` application component will be used. |
|
|
|
* If this parameter is not given, the `mongodb` application component will be used. |
|
|
|
* @return array the query results. If the query results in nothing, an empty array will be returned. |
|
|
|
* @return array the query results. If the query results in nothing, an empty array will be returned. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function all($db = null) |
|
|
|
public function all($db = null) |
|
|
@ -192,7 +192,7 @@ class Query extends Component implements QueryInterface |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Executes the query and returns a single row of result. |
|
|
|
* Executes the query and returns a single row of result. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* If this parameter is not given, the `mongo` application component will be used. |
|
|
|
* If this parameter is not given, the `mongodb` application component will be used. |
|
|
|
* @return array|boolean the first row (in terms of an array) of the query result. False is returned if the query |
|
|
|
* @return array|boolean the first row (in terms of an array) of the query result. False is returned if the query |
|
|
|
* results in nothing. |
|
|
|
* results in nothing. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -206,7 +206,7 @@ class Query extends Component implements QueryInterface |
|
|
|
* Returns the number of records. |
|
|
|
* Returns the number of records. |
|
|
|
* @param string $q kept to match [[QueryInterface]], its value is ignored. |
|
|
|
* @param string $q kept to match [[QueryInterface]], its value is ignored. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* If this parameter is not given, the `mongo` application component will be used. |
|
|
|
* If this parameter is not given, the `mongodb` application component will be used. |
|
|
|
* @return integer number of records |
|
|
|
* @return integer number of records |
|
|
|
* @throws Exception on failure. |
|
|
|
* @throws Exception on failure. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -229,7 +229,7 @@ class Query extends Component implements QueryInterface |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns a value indicating whether the query result contains any row of data. |
|
|
|
* Returns a value indicating whether the query result contains any row of data. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* If this parameter is not given, the `mongo` application component will be used. |
|
|
|
* If this parameter is not given, the `mongodb` application component will be used. |
|
|
|
* @return boolean whether the query result contains any row of data. |
|
|
|
* @return boolean whether the query result contains any row of data. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function exists($db = null) |
|
|
|
public function exists($db = null) |
|
|
@ -242,7 +242,7 @@ class Query extends Component implements QueryInterface |
|
|
|
* @param string $q the column name. |
|
|
|
* @param string $q the column name. |
|
|
|
* Make sure you properly quote column names in the expression. |
|
|
|
* Make sure you properly quote column names in the expression. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* If this parameter is not given, the `mongo` application component will be used. |
|
|
|
* If this parameter is not given, the `mongodb` application component will be used. |
|
|
|
* @return integer the sum of the specified column values |
|
|
|
* @return integer the sum of the specified column values |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function sum($q, $db = null) |
|
|
|
public function sum($q, $db = null) |
|
|
@ -255,7 +255,7 @@ class Query extends Component implements QueryInterface |
|
|
|
* @param string $q the column name. |
|
|
|
* @param string $q the column name. |
|
|
|
* Make sure you properly quote column names in the expression. |
|
|
|
* Make sure you properly quote column names in the expression. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* If this parameter is not given, the `mongo` application component will be used. |
|
|
|
* If this parameter is not given, the `mongodb` application component will be used. |
|
|
|
* @return integer the average of the specified column values. |
|
|
|
* @return integer the average of the specified column values. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function average($q, $db = null) |
|
|
|
public function average($q, $db = null) |
|
|
@ -281,7 +281,7 @@ class Query extends Component implements QueryInterface |
|
|
|
* @param string $q the column name. |
|
|
|
* @param string $q the column name. |
|
|
|
* Make sure you properly quote column names in the expression. |
|
|
|
* Make sure you properly quote column names in the expression. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* If this parameter is not given, the `mongo` application component will be used. |
|
|
|
* If this parameter is not given, the `mongodb` application component will be used. |
|
|
|
* @return integer the maximum of the specified column values. |
|
|
|
* @return integer the maximum of the specified column values. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function max($q, $db = null) |
|
|
|
public function max($q, $db = null) |
|
|
@ -323,7 +323,7 @@ class Query extends Component implements QueryInterface |
|
|
|
* Returns a list of distinct values for the given column across a collection. |
|
|
|
* Returns a list of distinct values for the given column across a collection. |
|
|
|
* @param string $q column to use. |
|
|
|
* @param string $q column to use. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* @param Connection $db the Mongo connection used to execute the query. |
|
|
|
* If this parameter is not given, the `mongo` application component will be used. |
|
|
|
* If this parameter is not given, the `mongodb` application component will be used. |
|
|
|
* @return array array of distinct values |
|
|
|
* @return array array of distinct values |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function distinct($q, $db = null) |
|
|
|
public function distinct($q, $db = null) |