[mongodb] mongodb paging display


Pagination with mongodb limit and skip method
Mongodb limit() method
If you need to read a specified number of data records in mongodb, you can use mongodb’s limit method. The limit () method accepts a number parameter, which specifies the number of records read from mongodb.
Mongodb skip() method
In addition to using the limit () method to read the specified number of data, we can also use the skip () method to skip the specified number of data. The skip method also accepts a number parameter as the number of records to skip.

PHP code


        $filter = [];
        //Pagination display
        $options = [
            'skip'=>($page - 1) * $pageSize,
            'sort' => ['createTime' => -1],
            'projection'=>['_id'=> False, "modelXML"=> False],

        $query = new MongoDB\Driver\Query($filter, $options);
        $mongoManger = new MongoDB\Driver\Manager("mongodb://");
        $cursor = $mongoManger->executeQuery($this->dbName.$collect, $query);