|
MongoCollection::findOneQueries this collection, returning a single element Description
public array MongoCollection::findOne
([ array
$query = array()
[, array $fields = array()
[, array $options = 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. Parameters
Return Values
Returns record matching the search or Errors/ExceptionsThrows MongoConnectionException if it cannot reach the database. Changelog
ExamplesExample #1 MongoCollection::findOne document by its id. This example demonstrates how to find a single document in a collection by its id.
<?php Example #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 The above example will output something similar to: 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. See Also
|