CollectionFind::limit

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

CollectionFind::limit — 반환되는 문서 수 제한


설명

public mysql_xdevapi\CollectionFind::limit(int $rows): mysql_xdevapi\CollectionFind

반환할 최대 문서 수를 설정합니다.


매개변수

rows
최대 문서 수.

반환 값

추가 처리에 사용할 수 있는 CollectionFind 개체입니다. DocResult 개체를 반환하기 위해 execute() 메서드와 연결합니다.


Examples

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

                  
<?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();
$create
  ->add('{"name": "Reginald", "age": 42, "job": "Butler"}')
  ->execute();


// ...

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

$result = $collection
  ->find('job like :job and age > :age')
  ->bind(['job' => 'Butler', 'age' => 16])
  ->sort('age desc')
  ->limit(1)
  ->execute();

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

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

array(1) {
  [0]=>
  array(4) {
    ["_id"]=>
    string(28) "00005b6b536100000000000000f3"
    ["age"]=>
    int(42)
    ["job"]=>
    string(6) "Butler"
    ["name"]=>
    string(8) "Reginald"
  }
}