[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);


Recommended Today

Timely communication best practices

describe Lhttp is a framework based on websocket server, which provides a protocol similar to HTTP to help developers develop long connected applications. Using lhttp can greatly reduce the workload of server development, and achieve very good modularity and decoupling of business functions. You can customize any function you want. Project address Characteristic Easy to […]