yii\mongodb\Query::count PHP Method

count() public method

Returns the number of records.
public count ( string $q = '*', Connection $db = null ) : integer
$q string kept to match [[QueryInterface]], its value is ignored.
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
return integer number of records
    public function count($q = '*', $db = null)
    {
        $collection = $this->getCollection($db);
        return $collection->count($this->where, $this->options);
    }

Usage Example

 public function actionCountList()
 {
     $accountId = $this->getAccountId();
     $keyword = $request = Yii::$app->request->get("keyword", '');
     if ($keyword == "undefined") {
         $keyword = '';
     }
     $query = new Query();
     $query->from('uhkklpCookingtype')->where(['isDeleted' => false])->andWhere(['accountId' => $accountId])->andWhere(['or', ['category' => '大類']])->andWhere(['like', 'name', $keyword]);
     $count = $query->count();
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 200, 'msg' => 'OK', 'result' => $count];
 }
All Usage Examples Of yii\mongodb\Query::count