Laravel-mongodb: Limit exception. Found string instead of an integer

Created on 19 Feb 2018  路  2Comments  路  Source: jenssegers/laravel-mongodb

Mango DB: v3.3.1
Laravel 5.5
Other packages: Datatables
I'm trying to use the query builder with datatables that makes the query based on params and etc, but Mango freaks out with the limit feature. It throws the error:

MongoDB\Exception\InvalidArgumentException: Expected "limit" option to have type "integer" but found "string" in I:\xampp\htdocs\ngis\vendor\mongodb\mongodb\src\Exception\InvalidArgumentException.php:32
Stack trace:
#0 I:\xampp\htdocs\ngis\vendor\mongodb\mongodb\src\Operation\Find.php(183):

Which I know if you type cast, it's fine, but is there a reason why Mongo isn't able to type cast? I couldn't figure out where Datatables is trying to build the query. It's similar to this issue: https://github.com/yajra/laravel-datatables/issues/1442

THANKS!

question

Most helpful comment

You have to use "intval" in both function of take && skip

$trans = DB::collection("collection_name")
         ->take( intval($limit) )
         ->skip( intval($skip) )->get();

All 2 comments

You have to use "intval" in both function of take && skip

$trans = DB::collection("collection_name")
         ->take( intval($limit) )
         ->skip( intval($skip) )->get();

You have to use "intval" in both function of take && skip

$trans = DB::collection("collection_name")
         ->take( intval($limit) )
         ->skip( intval($skip) )->get();

I have a similar problem but after print this: ErrorException: Illegal offset type in /var/www/html/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Query/Builder.php:383

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sebastiaanluca picture sebastiaanluca  路  3Comments

bastiendonjon picture bastiendonjon  路  3Comments

viacheslavpleshkov picture viacheslavpleshkov  路  3Comments

tomartailored picture tomartailored  路  3Comments

phuocduy1988 picture phuocduy1988  路  3Comments