I have a collection with information on visitors to a website, each visitor has various information about them including if a salesperson had them “locked” or not. Currently I have the following code:
$db = $conn->Surreal;
$collection = $db->visitors;
$criteria = array(
'locked_by' => $_REQUEST['ownerkey'],
);
$criteriat = array(
'locked_by' => null,
);
$cursor = $collection->find($criteria);
$cursort = $collection->find($criteriat);
//echo $doc->count() . ' document(s) found. <br/>';
foreach ($cursor as $doc) {
//List all
if($doc['locked_by'] ==null) $doc['locked_by'] = " ";
$pieces = explode("&&", $doc['location']);
echo('Surreal - '.$doc['name'].'//'.$doc['uuid'].'//'.$doc['uuid'].'//'.$doc['locked_by'].'//'.$doc['location'].'*');
}
foreach ($cursort as $doc) {
//List all
if($doc['locked_by'] ==null) $doc['locked_by'] = " ";
$pieces = explode("&&", $doc['location']);
echo('Surreal - '.$doc['name'].'//'.$doc['uuid'].'//'.$doc['uuid'].'//'.$doc['locked_by'].'//'.$doc['location'].'*');
}
Basically echoing out the information using two foreach statements. Can I somehow instead use a query to say basicly
if(locked_by == "RANDOM" || locked_by == null)
?
Well, MongoDB supports OR conditions in queries, starting from the 1.5.3 version:
… so it should be implemented by something like this:
The question it whether the driver you use supports this type of queries. I’ve faced some difficulties using this particular type, but that was a year ago; I suppose the things might get changed to best. )
UPDATE: at least there’s a similar query here in comments, so I guess the things DID change to best. )