1. 程式人生 > >mongodb分頁查詢,排序

mongodb分頁查詢,排序

字符 star skip 相對 代碼 php代碼 this post 倒序

mongodb代碼

根據時間倒序,查看10條
db.表名.find({"_id":"xxx"}).sort({"inserted":-1}).limit(10).skip(1)

  

相對的php代碼

  $postArr = $this->mongo->executeQuery(
            表名,
            [
                ‘_id‘ => new ObjectId(字符串id)
            ],
            [
                ‘sort‘ => [
                    ‘inserted‘ => -1
                ],
                ‘limit‘ => 10,
                ‘skip‘ => 1,
                ‘projection‘ => array(
                    ‘_id‘ => 1
                )
            ]
        );


  

mongodb分頁查詢,排序