The 5th Annual China PHP Conference

Setting Criteria for a Query

We can create a query to pass to the MongoCollection::find() method to get a subset of the documents in our collection. For example, if we wanted to find the document for which the value of the "i" field is 71, we would do the following:

= new MongoClient();
$collection $connection->database->collectionName;

$query = array( 'i' => 71 );
$cursor $collection->find$query );

while ( 
$cursor->hasNext() )
var_dump$cursor->getNext() );

The above example will output:

array(2) {
  object(MongoId)#6 (0) {
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top