CollectionFind::fields

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

CollectionFind::fields — 문서 필드 필터 설정


설명

public mysql_xdevapi\CollectionFind::fields(string $projection): mysql_xdevapi\CollectionFind

반환할 쿼리의 열을 정의했습니다. 정의되지 않은 경우 모든 열이 사용됩니다.


매개변수

projection
단일 문자열 또는 문자열 배열일 수 있으며 이러한 문자열은 검색 조건과 일치하는 각 문서에 대해 반환되어야 하는 열을 식별합니다.

반환 값

추가 처리에 사용할 수 있는 CollectionFind 개체입니다.


Examples

예제 #1 mysql_xdevapi\CollectionFind::fields() 예제

                  
<?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");
$create = $schema->createCollection("people");

$create
  ->add('{"name": "Alfred", "age": 18, "job": "Butler"}')
  ->execute();

// ...

$collection = $schema->getCollection("people");

$result = $collection
  ->find('job like :job and age > :age')
  ->bind(['job' => 'Butler', 'age' => 16])
  ->fields('name')
  ->execute();

var_dump($result->fetchAll());
?>
                  
                

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

array(1) {
  [0]=>
  array(1) {
    ["name"]=>
    string(6) "Alfred"
  }
}