note 116803 added to mongocollection.find
| From: | bronius dot motekaitis at gmail dot com | Date: | Mon, 02 Mar 2015 20:30:14 +0000 |
| Subject: | note 116803 added to mongocollection.find | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201840@lists.php.net to get a copy of this message | ||
As the docs specify, '$or' conditions (and similar) get passed right on to MongoDB
directly. It appears that to make a simple "field, $or, field" compound query work, all
parts must be wrapped as a gigantic $and.
Here's how I got a find(), findOne(), and findAndModify() to obey such a compound $or for
matching on fields, one of which is represented in data as either a string or integer:
<?php
$query =
array('$and' =>
array(
array('assessment_id' => $doc->assessment_id),
array('$or' =>
array(
array('participant_id' => $doc->participant_id),
array('participant_id' => (string)$doc->participant_id),
),
),
array('measure_id' => $doc->measure_id)
),
);
$thedoc = $collection->findOne($query);
return $thedoc;
?>
----
Server IP: 72.52.91.14
Probable Submitter: 75.108.6.21
----
Manual Page -- http://php.net/manual/en/mongocollection.find.php
Edit -- https://master.php.net/note/edit/116803
Del: integrated -- https://master.php.net/note/delete/116803/integrated
Del: useless -- https://master.php.net/note/delete/116803/useless
Del: bad code -- https://master.php.net/note/delete/116803/bad+code
Del: spam -- https://master.php.net/note/delete/116803/spam
Del: non-english -- https://master.php.net/note/delete/116803/non-english
Del: in docs -- https://master.php.net/note/delete/116803/in+docs
Del: other reasons-- https://master.php.net/note/delete/116803
Reject -- https://master.php.net/note/reject/116803
Search -- https://master.php.net/manage/user-notes.php