php查詢mongo過濾的條目數

    /**
     * 獲取mongo篩選查詢的條目
     * @param $db string 數據庫
     * @param $collection string 集合名
     * @param $filter array 過濾條件
     * @return mixed 返回個數
     * @throws \MongoDB\Driver\Exception\Exception
     */
    public function count($db,$collection,$filter = [])
    {
        //查詢條件
        $command = new Command(
            [
                'count' => $collection,
                'query' => $filter,
            ]
        );
        return $this->client()->executeCommand($db,$command)->toArray()[0]->n;
    }
    ```
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章