CollectionModify::limit

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

CollectionModify::limit — 수정된 문서 수 제한


설명

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

이 작업으로 수정된 문서 수를 제한합니다. 선택적으로 skip()과 결합하여 오프셋 값을 정의합니다.


매개변수

rows
수정할 최대 문서 수입니다.

반환 값

CollectionModify 개체입니다.


Examples

예제 #1 mysql_xdevapi\CollectionModify::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");
$collection = $schema->createCollection("people");

$collection->add('{"name": "Fred",  "age": 21, "job": "Construction"}')->execute();
$collection->add('{"name": "Wilma", "age": 23, "job": "Teacher"}')->execute();
$collection->add('{"name": "Betty", "age": 24, "job": "Teacher"}')->execute();

$collection
  ->modify("job = :job")
  ->bind(['job' => 'Teacher'])
  ->set('job', 'Principal')
  ->limit(1)
  ->execute();

$result = $collection
  ->find()
  ->execute();

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

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

Array
(
    [0] => Array
        (
            [_id] => 00005b6b53610000000000000118
            [age] => 21
            [job] => Construction
            [name] => Fred
        )
    [1] => Array
        (
            [_id] => 00005b6b53610000000000000119
            [age] => 23
            [job] => Principal
            [name] => Wilma
        )
    [2] => Array
        (
            [_id] => 00005b6b5361000000000000011a
            [age] => 24
            [job] => Teacher
            [name] => Betty
        )
)