Collection::getOne

(사용 가능한 버전 정보가 없으며 Git에만 있을 수 있음)

Collection::getOne — 하나의 문서 가져오기


설명

public mysql_xdevapi\Collection::getOne(string $id): Document

컬렉션에서 하나의 문서를 가져옵니다.

이것은 바로 가기입니다. Collection.find("_id = :id").bind("id", id).execute().fetchOne();


매개변수

id
컬렉션의 문서 _id입니다.

반환 값

컬렉션 개체 또는 _id가 문서와 일치하지 않는 경우 null입니다.


Examples

예제 #1 mysql_xdevapi\Collection::getOne() 예제

                  
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();

$schema     = $session->getSchema("addressbook");
$collection = $schema->createCollection("people");

$result = $collection->add('{"name": "Alfred", "age": 42, "job": "Butler"}')->execute();

// A unique _id is (by default, and recommended) generated by MySQL Server
// This retrieves the generated _id's; only one in this example, so $ids[0]
$ids        = $result->getGeneratedIds();
$alfreds_id = $ids[0];

// ...

print_r($alfreds_id);
print_r($collection->getOne($alfreds_id));
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

00005b6b536100000000000000b1

Array
(
    [_id] => 00005b6b536100000000000000b1
    [age] => 42
    [job] => Butler
    [name] => Alfred
)