mongo sort after limit after sort - Not working

后端 未结 5 1134
囚心锁ツ
囚心锁ツ 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 03:06

    I am using the following code in php5 and mongodb latest build:

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

    It stops working when I use ->skip(1999)->limit(1) after sort()

    The cursor $doc does give me values . I tried braking it down into this:

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

    That worked. May be you should try that in new versions.

提交回复
热议问题