Doctrine2 Mongodb 添加更多 $or 运算符 [英] Doctrine2 Mongodb adding more $or operator

查看:20
本文介绍了Doctrine2 Mongodb 添加更多 $or 运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

doctor2 ODM 是否可以创建以下查询?

It is possible for doctrine2 ODM to create the following query?

db.Product.find({ "$or": [ { "name": new RegExp("test*", "i") }, { "tags": new RegExp("public true*", "i") } ], "$or": [{ "public": false, "_id": { "$in": [ ObjectId("4e74121c4fcfa9ff7ac90000"), ObjectId("4e74121c4fcfa9ff7ac80000") ] } }, { "public": true }] });

我不明白的关于 doterin2 的主要问题是如何在 $query 中添加加法 $or?

The main issue here with doctrine2 that I dont understand is how to add addition $or in the $query?

这可以帮助我解决仍然缺少的 $and 运算符.

This help me with $and operator which is still missing.

我目前使用的是 Symfony2 Doctrine2 Mongodb

I'm currently using Symfony2 Doctrine2 Mongodb

推荐答案

/**
 * 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
 */

这篇关于Doctrine2 Mongodb 添加更多 $or 运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆