Closed benargo closed 4 years ago
I've noticed that the same exception is thrown on Builder::count()
too.
I think I've determined this is because both the count
and paginate
functions cause aggregations, and I don't think there's much we can do about this. I guess I'll just have to stick with simplePagination
.
@benargo Did you ever solve this without resulting to not using paginate and count. I have also made a similar observation as you have
Alas not.
However, if you are keen on having length-aware pagination you could always manually create a paginator by slicing the collection.
Thanks
Distance operators like $near
and $nearSphere
have a different behavior on sorting/skipping.
If it's okay for you to find the addresses in a specific area without distance sorting you can also use the geoWithin
operator. This operator works fine with pagination functions.
Model::where('address', 'geoWithin', [
'$centerSphere' => [
[
4.1450383,
51.5069158,
],
50 / 3963.2 // 50 mile (3963.2 = equatorial radius of the earth)
]
])->paginate(12);
Description:
MongoDB\Driver\Exception\RuntimeException in
./vendor/mongodb/mongodb/src/Operation/Aggregate.php
line 219:$near is not allowed inside of a $match aggregation expression
Steps To Reproduce:
I'm trying to paginate the results of a geospatial query. If I simply run
->get()
(without pagination) then the results return fine.I've been following the advice given in #371 to run geospatial queries, as you will see below.
File:
VenueListController.php