ModelBundle/Repository/SiteRepository.php
public function findByAliasDomain($domain)
    {
        $database = $this->dm->getDocumentDatabase($this->documentName);
        $collectionName = $this->dm->getClassMetadata($this->documentName)->collection;

        $map = new \MongoCode(
            'function(){
                for (var i in this.aliases) {
                    if (this.aliases[i].domain == domain) {
                        emit(this.siteId, this.siteId);
                    }
                }
            }'
        );
        $reduce = new \MongoCode("function(key, values) { return values[0]; }");

        $commandResult = $database->command(array(
            "mapreduce" => $collectionName,
            "map" => $map,
            "reduce" => $reduce,
            "out" => array("inline" => 1),
            "scope" => array(
                "domain" => "$domain"
            )
        ));

        $ids = array();
        if (is_array($commandResult) && array_key_exists('ok', $commandResult) && $commandResult['ok'] == 1) {
            foreach ($commandResult['results'] as $siteId) {
                $ids[] = $siteId['_id'];
            }
        }

        $qb = $this->createQueryBuilder();
        $qb->field('siteId')->in($ids);

        return $qb->getQuery()->execute();
    }
public function findByAliasDomain($domain)
    {
        $database = $this->dm->getDocumentDatabase($this->documentName);
        $collectionName = $this->dm->getClassMetadata($this->documentName)->collection;

        $map = new \MongoCode(
            'function(){
                for (var i in this.aliases) {
                    if (this.aliases[i].domain == domain) {
                        emit(this.siteId, this.siteId);
                    }
                }
            }'
        );
        $reduce = new \MongoCode("function(key, values) { return values[0]; }");

        $commandResult = $database->command(array(
            "mapreduce" => $collectionName,
            "map" => $map,
            "reduce" => $reduce,
            "out" => array("inline" => 1),
            "scope" => array(
                "domain" => "$domain"
            )
        ));

        $ids = array();
        if (is_array($commandResult) && array_key_exists('ok', $commandResult) && $commandResult['ok'] == 1) {
            foreach ($commandResult['results'] as $siteId) {
                $ids[] = $siteId['_id'];
            }
        }

        $qb = $this->createQueryBuilder();
        $qb->field('siteId')->in($ids);

        return $qb->getQuery()->execute();
    }
@param string $domain

@return \Doctrine\ODM\MongoDB\Cursor