Closed Webixel closed 9 months ago
Hi @Webixel,
what version of the driver are you running? You can find out the version of the MongoDB library by running composer show mongodb/mongodb
, and the extension version by running php --ri mongodb
. Also, this error shouldn't occur as we're always assigning an array type map (i.e. embedded documents are always returned as PHP arrays), so I'd be curious to know how you create the DocumentManager
and the MongoDB\Client
instance it takes. Can you show the code you use to bootstrap the ODM?
Hi @alcaeus , thank you for the quick reply.
composer show mongodb/mongodb
name : mongodb/mongodb
descrip. : MongoDB driver library
keywords : database, driver, mongodb, persistence
versions : * 1.17.0
type : library
license : Apache License 2.0 (Apache-2.0) (OSI approved) https://spdx.org/licenses/Apache-2.0.html#licenseText
homepage : https://jira.mongodb.org/browse/PHPLIB
source : [git] https://github.com/mongodb/mongo-php-library.git 9d9c917cf7ff275ed6bd63c596efeb6e49fd0e53
php --ri mongodb
mongodb
MongoDB support => enabled
MongoDB extension version => 1.17.0
MongoDB extension stability => stable
libbson bundled version => 1.25.1
libmongoc bundled version => 1.25.1
...
<?php
use Doctrine\MongoDB\Connection,
Doctrine\ODM\MongoDB\Configuration,
Doctrine\ODM\MongoDB\DocumentManager,
Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
use MongoDB\Client;
...
private function setDocumentManager(){
$documentsDirectory = __DIR__ . '/Documents';
$serverAddress = 'mongodb://127.0.0.1:27017';
$config = new Configuration();
$config->setProxyDir(sys_get_temp_dir() . '/proxies');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir(sys_get_temp_dir() . '/hydrators');
$config->setHydratorNamespace('Hydrators');
$config->setMetadataDriverImpl(AnnotationDriver::create($documentsDirectory));
$config->setDefaultDB('mydb');
return DocumentManager::create(new Client($serverAddress), $config);
}
...
Thanks for the information. It took me a moment to find this, as our tests still manually set a typeMap
, which wasn't required since #2288. Once I removed that type map I was able to reproduce the issue and fix it: #2600. This will be released in 2.6.2.
Yes, thanks. It works by modifying in the mongo client
return DocumentManager::create(new Client($serverAddress, [], ['typeMap' => DocumentManager::CLIENT_TYPEMAP]), $config);
Bug Report
Summary
When I want to retrieve the metadata of the newly inserted file, I get a hydrator error that returns to me.
Current behavior
Throws a fatal error when property is accessed:
Fatal error: Uncaught Doctrine\ODM\MongoDB\Hydrator\HydratorException: Expected association for field "metadata" in document of type "Documents\Fichier" to be of type "array", "object" received.
How to reproduce
Controller
Fichier Document
Fichiermetadata Document
Expected behavior
I want to retrieve an array or an object with the different metadata of the file saved previously