Open bazo opened 5 years ago
@bazo are you creating connection on your own? If yes then ODM requires certain settings of typeMap or will throw an exception as it couldn't work otherwise (as per #1871)
connection no, but client yes like this
$client = new Client($config['uri'], $config['mongoOptions']);
$dm = DocumentManager::create($client, $configuration, $evm);
it's actually this file https://github.com/bazo/nette-document-manager-extension/blob/master/src/Bazo/MongoDb/DI/DocumentManagerExtension.php#L134
Yup, meant Client :) Leaving a note here so it won't get lost. @jmikola said:
I was going to suggest withOptions() to override the type map, but I realize now that's only available on the Database and Collection objects. I'm curious if ODM could also just work around this and pass a default type map when it creates those two objects from a Client, and then use the same default type map for any Client methods it needs to access directly (those are the only other things that would inherit the Client-level type map)
Quick update: this is currently waiting on https://github.com/mongodb/mongo-php-library/pull/599, which is most likely going to land in version 1.5.0 of mongodb/mongodb
. There is DocumentManager::CLIENT_TYPEMAP
which has to be used when manually creating a DocumentManager. Once we're able to require mongodb/mongodb
1.5.0 or newer (which will be in a future 2.x release), the exception will be removed, with the DocumentManager creating a copy of the client with the correct typeMap. Until then, I've created https://github.com/bazo/nette-document-manager-extension/pull/3 to work around this.
Any updates on this?
Yes: we've decided to not implement a Client::withOptions
helper in the MongoDB Driver, due to its implications on the underlying extensions. If you are creating your collections manually, you currently will have to pass the correct type map. We'll be working around this in a different way by passing a typeMap
option to all find
calls manually, which means that we can reuse existing connections that may have an incompatible typeMap set.
Bug Report
Summary
ODM throws exception Invalid typemap provided. Type "array" is required for "root" but root is BSONDocument
Current behavior
Exception is thrown
Expected behavior
No exception