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;
    }
    ```
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章