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

gp187 picture gp187  路  19Comments

trololosha4real picture trololosha4real  路  20Comments

microwavekonijn picture microwavekonijn  路  20Comments

phongtnit picture phongtnit  路  27Comments

dhananjaygoel picture dhananjaygoel  路  17Comments