Рекурсивный акроним словосочетания «PHP: Hypertext Preprocessor»
Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 17695 программистов и 1736 роботов. Сейчас ищут 1295 программистов ...
Getting A Set of Documents With a Query
Вернуться к: Tutorial
We can use the query to get a set of documents from our collection. For example, if we wanted to get all documents where "i" > 50, we could write:
<?php
$connection = new MongoClient();
$collection = $connection->database->collectionName;
$query = array( "i" => array( '$gt' => 50 ) ); //note the single quotes around '$gt'
$cursor = $collection->find( $query );
while ( $cursor->hasNext() )
{
var_dump( $cursor->getNext() );
}
?>
which should print the documents where "i" > 50. We could also get a range, say 20 < i <= 30:
<?php $connection = new MongoClient(); $collection = $connection->database->collectionName; $query = array( 'i' => array( '$gt' => 20, "\$lte" => 30 ) ); $cursor = $collection->find( $query ); while ( $cursor->hasNext() ) { var_dump( $cursor->getNext() ); } ?>
Remember to always escape the $-symbol or use single quotes. Otherwise PHP will interpret it to be the variable $gt.
Вернуться к: Tutorial