mongo sort after limit after sort - Not working

后端 未结 5 1125
囚心锁ツ
囚心锁ツ 2020-12-18 02:38

I have a collection, from which i get particular type of users using $query
Then I need sort them according to user_id ascending and limit them to 2000

From t

5条回答
  •  执念已碎
    2020-12-18 02:46

    How about using skip():

    $cursor = $collection   ->find($query)  
            ->sort(array('user_id'=>1))   
            ->limit(2000)                
            ->skip(1999);
    

提交回复
热议问题