MongoCollection::findOne(PECL mongo >=0.9.0) MongoCollection::findOne — Querys this collection, returning a single element Описание
public array MongoCollection::findOne
([ array $query = array()
[, array $fields = array()
]] )
As opposed to MongoCollection::find(), this method will return only the first result from the result set, and not a MongoCursor that can be iterated over. Список параметров
Возвращаемые значенияReturns record matching the search or NULL. ОшибкиThrows MongoConnectionException if it cannot reach the database. ПримерыПример #1 MongoCollection::findOne() document by its id. This example demonstrates how to find a single document in a collection by its id.
<?phpПример #2 MongoCollection::findOne() document by some condition. This example demonstrates how to find a single document in a collection by some condition and limiting the returned fields.
<?phpРезультатом выполнения данного примера будет что-то подобное:
Array
(
[_id] => MongoId Object
(
)
[password] => test
)
Notice how even though the document does have a username field, we limited the results to only contain the password field. Смотрите также
|
||