Closed nationdata-it closed 4 years ago
@nationdata-it please provide a stacktrace.
@nationdata-it at a glance it seems that either $collection_object_id
or $session_user
is a bool.
yes initial i was thinking that i'm sending wrong values to confirm that i changed the call to something like this.
$collection_object_id = new ObjectId('5ecd55047ac60e4c2c1f1234'); $session_user = new ObjectId('5e6843962aca3953e42efd00'); $criteria = [ 'collection_object_id' => $collection_object_id, 'employee_id' => $session_user, 'form_cabinet_id' => ['$exists' => false] ]; $dm->getRepository(self::getClassName())->findBy($criteria, $sort)
stack trace @Steveb-p
( ! ) Fatal error: Uncaught TypeError: MongoDB\BSON\ObjectId::construct() expects parameter 1 to be string, boolean given in /var/www/project/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Types/ObjectIdType.php on line 20 ( ! ) TypeError: MongoDB\BSON\ObjectId::construct() expects parameter 1 to be string, boolean given in /var/www/project/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Types/ObjectIdType.php on line 20 Call Stack
Time Memory Function Location
1 0.0037 414904 {main}( ) .../index.php:0 2 0.2908 4849104 src\helpers\Slim->run( ) .../index.php:54 3 0.2908 4849080 Slim\Middleware\MethodOverride->call( ) .../Slim.php:1300 4 0.2966 4880344 Slim\Middleware\Flash->call( ) .../MethodOverride.php:92 5 0.2966 4880720 src\helpers\Slim->call( ) .../Flash.php:85 6 0.3010 5046472 Slim\Route->dispatch( ) .../Slim.php:1355 7 0.3792 5645520 call_user_func_array:{/var/www/project/vendor/slim/slim/Slim/Route.php:468} ( ) .../Route.php:468 8 0.3792 5645584 Slim\Route->Slim{closure:/var/www/project/vendor/slim/slim/Slim/Route.php:168-174}( ) .../Route.php:468 9 0.6279 8222752 call_user_func_array:{/var/www/project/vendor/slim/slim/Slim/Route.php:173} ( ) .../Route.php:173 10 0.6279 8222760 src\controllers\Controller_Dashboard->index( ) .../Route.php:173 11 0.7456 8717896 Doctrine\ODM\MongoDB\Repository\DocumentRepository->findBy( ) .../controller_dashboard.php:47 12 0.7681 9349736 Doctrine\ODM\MongoDB\Persisters\DocumentPersister->loadAll( ) .../DocumentRepository.php:160 13 0.7681 9349736 Doctrine\ODM\MongoDB\Persisters\DocumentPersister->prepareQueryOrNewObj( ) .../DocumentPersister.php:504 14 0.7682 9350864 Doctrine\ODM\MongoDB\Persisters\DocumentPersister->convertToDatabaseValue( ) .../DocumentPersister.php:1015 15 0.7682 9350864 Doctrine\ODM\MongoDB\Persisters\DocumentPersister->convertToDatabaseValue( ) .../DocumentPersister.php:1045 16 0.7682 9350864 Doctrine\ODM\MongoDB\Types\ObjectIdType->convertToDatabaseValue( ) .../DocumentPersister.php:1069 17 0.7682 9350944 __construct ( )
query debug:
`Array ( [0] => Array ( [type] => 1 [query] => Array ( [collection_object_id] => MongoDB\BSON\ObjectId Object ( [oid] => 5ecd55047ac60e4c2c1f266e )
[employee_id] => MongoDB\BSON\ObjectId Object
(
[oid] => 5e6843962aca3953e42e2d99
)
[form_cabinet_id] => Array
(
[$exists] =>
)
)
[newObj] => Array
(
)
)
)`
Ah this seems to be connected with #2194 and #2193 - it seems we're too eagerly trying to convert values ignoring expressions
@nationdata-it would you mind checking if #2205 fixes your issue?
Closing as #2205 was merged
Bug Report
Summary
when querying the database it generates error
`file.php /* @ODM\Field(type="object_id") / private $collection_object_id;
`
$files = $dm->createQueryBuilder(File::class) ->field('collection_object_id')->equals(new ObjectId($collection_object_id)) ->field('employee_id')->equals(new ObjectId($session_user)) ->field('form_cabinet_id')->exists(false) ->getQuery() ->execute();
or
$criteria = [ 'collection_object_id' => new ObjectId($collection_object_id), 'employee_id' => new ObjectId($session_user), 'form_cabinet_id' => ['$exists' => false] ]; $dm->getRepository(self::getClassName())->findBy($criteria, $sort)
Current behavior
Fatal error: Uncaught TypeError: MongoDB\BSON\ObjectId::__construct() expects parameter 1 to be string, boolean given in /var/www/project/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Types/ObjectIdType.php on line 20
How to reproduce
Expected behavior
should return records from db