I'm trying to execute a mongo find with php using the $and operator combined with the $or operator, however I cant seem to figure out the way to execute it. What this Query is trying to accomplish is search for folder=>INBOX
and match the email query for either recipient
or from
. Here's how I am trying to do it:
Query:
$query['$and'][]['$or'][]['to']['$regex'] = new MongoRegex("/".$_GET['term'].".*/i");
$query['$and'][]['$or'][]['from']['$regex'] = new MongoRegex("/".$_GET['term'].".*/i");
$query['$and'][]['$or'][]['recipient']['$regex'] = new MongoRegex("/".$_GET['term'].".*/i");
$query['$and'][]['folder'] = $_GET['folder'];
Print Pre:
Array
(
[$and] => Array
(
[0] => Array
(
[$or] => Array
(
[0] => Array
(
[to] => Array
(
[$regex] => MongoRegex Object
(
[regex] => example@example.com.*
[flags] => i
)
)
)
)
)
[1] => Array
(
[$or] => Array
(
[0] => Array
(
[from] => Array
(
[$regex] => MongoRegex Object
(
[regex] => example@example.com.*
[flags] => i
)
)
)
)
)
[2] => Array
(
[$or] => Array
(
[0] => Array
(
[recipient] => Array
(
[$regex] => MongoRegex Object
(
[regex] => example@example.com.*
[flags] => i
)
)
)
)
)
[3] => Array
(
[folder] => INBOX
)
)
)