本文介绍了Doctrine2 Mongodb添加更多$或运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
doctrine2 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 }] });
我不明白的doctrine2的主要问题是如何添加$或$查询?
The main issue here with doctrine2 that I dont understand is how to add addition $or in the $query?
这有助于我与$和运算符仍然缺少。
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添加更多$或运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!