0

I have been using https://github.com/jenssegers/laravel-mongodb package for interacting with MongoDB. Whenever I fetch a document without skip(), take() and orderBy(), I do not get any duplicate entries. However when I apply skip(), take() and orderBy() to the document, there are duplicate entries on different pages e.g. page 1 have an object with ID 123 and page 2 also have the same object with ID 123.

Please note that there are no duplicates in Mongo DB.

Here is how I am trying to do this:

    $record = Model::where('filter1', $algorithm) ->where('filter2', '>=', $asofdate) ->where('filter2', '<', $nextDay);
    $record->project(['_id' => 0])->skip($skip)->take($pageSize)->orderBy('column1', 'desc')->get(['column1','column2']); 

I also tried using the raw query provided by the package but the issue is still same.

    $record = Tree::raw(function($collection) use ($asofdate, $nextDay) { 
        return $collection->find( [ 
                "$and" => [ 
                     ["filter1" => "blind_popularity"], 
                    ["filter2" => ["$gte" => $asofdate]], 
                    ["filter2" => ["$lt" => $nextDay]], 
                    ["filter1" => ["$in" => [22]]] ] 
                ], 
                [ "column1" => 1, "column2"=>1, "column3"=>1, "column4"=>1, 
                "column5"=>1, "_id"=>0 ], 
                [ "skip" => 0, "limit" => 15, "sort" => ["column1"=>1] 
                ]);
            });

Anybody have interaction with problem like this ?, share your thoughts to solve it.

0 Answers0