Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何创建一个。。。或在Symfony2中使用MongoDB进行查询?_Mongodb_Symfony_Doctrine Orm_Symfony 2.1_Doctrine Odm - Fatal编程技术网

如何创建一个。。。或在Symfony2中使用MongoDB进行查询?

如何创建一个。。。或在Symfony2中使用MongoDB进行查询?,mongodb,symfony,doctrine-orm,symfony-2.1,doctrine-odm,Mongodb,Symfony,Doctrine Orm,Symfony 2.1,Doctrine Odm,在我的UserRepository中,我想创建自定义查询,就像我不使用MongoDB时可以使用$dm->createQuery('some query')创建的查询一样 我该怎么做?我看到$this->createQueryBuilder()方法存在,但$this->createQuery()不存在 我也尝试过这样做,因为这是有意义的,但没有成功: $this->createQueryBuilder('u') ->where(array('$or' => array(

在我的
UserRepository
中,我想创建自定义查询,就像我不使用MongoDB时可以使用
$dm->createQuery('some query')
创建的查询一样

我该怎么做?我看到
$this->createQueryBuilder()
方法存在,但
$this->createQuery()
不存在

我也尝试过这样做,因为这是有意义的,但没有成功:

$this->createQueryBuilder('u')
    ->where(array('$or' => array(
        array('u.username' => $username),
        array('u.email' => $username)
    )))
    // ...
它说$or是无效的运算符。

在此处找到它:

/**
 * Adds an "or" expression to the current query.
 *
 * You can create the expression using the expr() method:
 *
 *     $qb = $this->createQueryBuilder('User');
 *     $qb
 *         ->addOr($qb->expr()->field('first_name')->equals('Kris'))
 *         ->addOr($qb->expr()->field('first_name')->equals('Chris'));
 *
 * @param array|QueryBuilder $expression
 * @return Builder
 */



/**
 * Adds an "and" expression to the current query.
 *
 * You can create the expression using the expr() method:
 *
 *     $qb = $this->createQueryBuilder('User');
 *     $qb
 *         ->addAnd($qb->expr()->field('first_name')->equals('Kris'))
 *         ->addAnd($qb->expr()->field('first_name')->equals('Chris'));
 *
 * @param array|QueryBuilder $expression
 * @return Query
 */