Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB ODM deserialisation issues #310

Open
vershart opened this issue May 16, 2024 · 0 comments
Open

MongoDB ODM deserialisation issues #310

vershart opened this issue May 16, 2024 · 0 comments

Comments

@vershart
Copy link

Hi!

I have tried to setup this adapter in a legacy app. When I am executing MongoDB ODM queries in the setup with the mongo-php-adapter, I have the error below returned by Doctrine for the following snippets:

$result = $this
            ->createQueryBuilder()
            ->field('someId')->equals(new MongoId($dto->getId()))
            ->hydrate(true)
            ->field('someField')->notEqual(true)
            ->getQuery()
            ->execute();

die(json_decode($result)); // As an example, originally the function returned the query builder ( \Doctrine\MongoDB\Query\Builder), which was then passed to Knp paginator
Error: Cannot use object of type MyBundle\Document\SomeDocument as array
    at n/a
        in /var/www/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php line 2687

The code fragment that returns with Symfony Stack Trace is as follows:

in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php at line 268
        $isManagedObject = false;
        if (! $class->isQueryResultDocument) {
            $id = $class->getDatabaseIdentifierValue($data['_id']);
            $serializedId = serialize($id);
            $isManagedObject = isset($this->identityMap[$class->name][$serializedId]);
        }

No other useful information was provided.

Now having the following configuration:

  • PHP 5.6.40
  • ext-mongodb 1.7.5
  • Version of the adapter installed: 1.2.5
  • The ext-mongo is not installed
  • MongoDB 4.4

composer.json related libraries:

        "alcaeus/mongo-php-adapter": "1.2.5",
        "doctrine/annotations": "v1.2.7",
        "doctrine/cache": "v1.4.2",
        "doctrine/collections": "v1.3.0",
        "doctrine/common": "v2.4.3",
        "doctrine/data-fixtures": "v1.1.1",
        "doctrine/dbal": "2.5.13",
        "doctrine/doctrine-bundle": "1.6.13",
        "doctrine/doctrine-cache-bundle": "1.3.0",
        "doctrine/doctrine-fixtures-bundle": "v2.4.1",
        "doctrine/inflector": "v1.0.1",
        "doctrine/instantiator": "1.0.5",
        "doctrine/lexer": "v1.0.1",
        "doctrine/mongodb": "1.6.4",
        "doctrine/mongodb-odm": "1.2.11",
        "doctrine/mongodb-odm-bundle": "3.4.4",
        "doctrine/orm": "v2.4.8",
        "mongodb/mongodb": "1.0.1",

PHP 5.6 sounds a bit of bad manners in 2024, I know.

Currently, there is a mix of Doctrine ODM usages and MongoDB driver usages. We are trying to move from the Mongo 3.4 to the latest version possible (it seems to be mostly compatible with MongoDB 4.4) to start decoupling and splitting our big legacy app and shutting it down.

I will be glad for any help or advice, thank you in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant