Reputation: 21
How can I write a query in yii mongodb with OR
condition.
For example, in SQL we can write the query like below
select * from tablename where fieldname = value1 or fieldname1 = value1
How can I write this in yii mongodb as i have to check whether a particular value is available in two fields in mongodb collection.
Upvotes: 0
Views: 1378
Reputation: 65363
Assuming you are using YiiMongoDBSuite (YMDS), lack of $or
support is noted as a current limitation of that extension:
In it's current incarnation, This extension does NOT work with the "$or" criteria operator. When we get it working we will remove this line and add an example.
Unfortunately the YMDS extension is not actively maintained, and does not support the full complement of features available in the MongoDB query language.
A recommended alternative would be to use the officially supported MongoDB PHP driver:
<?php
$cursor = $collection->find(
array(
'$or' => array(
"fieldname" => "value1",
"fieldname1" => "value2"
)
)
);
?>
Upvotes: 1