|
MongoCollection::findOneQueries this collection, returning a single element Description
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. Parameters
Return Values
Returns record matching the search or Errors/ExceptionsThrows MongoConnectionException if it cannot reach the database. ExamplesExample #1 MongoCollection::findOne document by its id. This example demonstrates how to find a single document in a collection by its id.
<?phpExample #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.
<?phpThe 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
|