Querying by nested references values in mongodb / doctrine2 odm

By : Michal
Source: Stackoverflow.com
Question!

Hello ive got the following code:

        $primer = function($dm, $className, $fieldName, $ids, $hints) {
        $repository = $dm->getRepository($className);
        $qb = $repository->createQueryBuilder()
            ->field('id')->in($ids)
            ->field('images')->prime(true);
        $query = $qb->getQuery();
        $query->execute()->toArray();
    };

    $qb = $followRepo
        ->createQueryBuilder()
        ->field('isActive')->equals(true)
        ->field('target')->prime($primer)
        ->field('follower')->references($return['user'])
        ->field('target.$ref')->equals('boards')
        ->field('target.createdBy.type')->equals('user') // here i dont know how to handle this
        ->sort('created', 'desc')

Is it even possible in mongo to query via target.createdBy.type? target.createdBy is also ref.

By : Michal


Answers
Yes, it is possible to query on sub document properties using the dot notation, as per the official documentation. I am pretty sure it wont work with a referencing in 1 step though.



This video can help you solving your question :)
By: admin