update : 2015.11.03
php.shukuma.com검색:
|
MongoCollection::findOne(PECL mongo >=0.9.0) MongoCollection::findOne — Queries this collection, returning a single element 설명
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. 인수
반환값
Returns record matching the search or 오류/예외Throws MongoConnectionException if it cannot reach the database. 변경점
예제Example #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 위 예제의 출력 예시: 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. 참고
|