MongoCollection::ensureIndex
MongoCollection::findOne
MongoCollection
PHP Manual

# MongoCollection::find

(PECL mongo >=0.9.0)

MongoCollection::find — Querys this collection

### Beschreibung

public MongoCursor MongoCollection::find ([ array `$query` = array() [, array `$fields` = array() ]] )

### Parameter-Liste

`query`

  The fields for which to search.

`fields`

  Fields of the results to return.

### Rückgabewerte

Returns a cursor for the search results.

### Beispiele

Beispiel #1 MongoCollection::find() example

This example demonstrates how to search for a range.

`<?php
// search for documents where 5 < x < 20
$rangeQuery = array('x' => array( '$gt' => 5, '$lt' => 20 ));
$cursor = $collection->find($rangeQuery);
?>`

See MongoCursor for more information how to work with cursors.

Beispiel #2 MongoCollection::find() example using $where

This example demonstrates how to search a collection using javascript code to reduce the resultset.

`<?php
$collection = $db->my_db->articles;
$js = "function() {
return this.type == 'homepage' || this.featured == true;
}";
$articles = $collection->find(array('$where' => $js));
?>`

Beispiel #3 MongoCollection::find() example using $in

This example demonstrates how to search a collection using the $in operator.

`<?php
$collection = $db->my_db->articles;
$articles = $collection->find(array(
'type' => array('$in' => array('homepage', 'editorial'))
));
?>`

### Siehe auch

MongoDB core docs on » find.

MongoCollection::ensureIndex
MongoCollection::findOne
MongoCollection
PHP Manual