Database Reference
In-Depth Information
[Address] => Array (
[Street] => 681 Hinkle Lake Road
[Place] => Newton
[Postal Code] => MA 02160
[Country] => USA
)
[E-Mail] => Array (
[0] =>
pm@example.com
[1] =>
pm@office.com
[2] =>
philip@example.com
[3] =>
philip@office.com
[4] =>
moran@example.com
[5] =>
moran@office.com
[6] =>
pmoran@example.com
[7] =>
pmoran@office.com
)
[Phone] => 617-546-8428
[Age] => 60
)
You can use the
$lte
operator to specify that the value must either match exactly or be lower than the value
specified. Remember:
$lt
will find anyone who is younger than 30, but not anyone who is exactly 30. The same goes
for the
$gte
operator, which finds any value that is greater than or equal to the integer specified. Now let's look at a
pair of examples.
The first example will return both items from your collection to your screen:
// Connect to the database
$c = new MongoClient();
// Select the collection 'people' from the database 'contacts'
$collection = $c->contacts->people;
// Specify the conditional operator
$cond = array('Age' => array('$lte' => 60));
// Execute the query and store it under the $cursor variable
$cursor = $collection->find($cond);
//Print the results
while($document = $cursor->getNext())
{
print_r($document);
}
The second example will display only one document because the collection only holds one contact who is either
60 or older:
// Connect to the database
$c = new MongoClient();
// Select the collection 'people' from the database 'contacts'
$collection = $c->contacts->people;
// Specify the conditional operator
$cond = array('Age' => array('$gte' => 60));