doeas anybody use the Query\Builder from Doctrine as Standalone Tool ?
It seems like The Query Manager needs a defined Class of the requested Document in MongoDB.
If you have a defined Class like:
<?php
namespace Documents;
/** @Document */
class User
{
// ...
/** @Field(type="string") */
private $username;
}
Then you can do the following:
<?php
$user = $dm->createQueryBuilder('User')
->field('username')->equals('jwage')
->getQuery()
->getSingleResult();
Is there a way to do use the Query\Builder without defining the Document Classes ?
Thanks in advance for any help.
You can use the QueryBuilder as soon as you have ClassMetaData. This class metadata is about mapping class properties to internal information, such as data types, associations, ...
You can define this class metadata without having real classes.
There are different approaches, but one of them would be to use the Doctrine\ODM\MongoDB\Tools\DisconnectedClassMetadataFactory
class, and feed related information using yaml or xml mapping.
You will have to configure your DocumentManager with the good classMetadataFactoryName
option.