Documentation Home
MySQL PHP API
Download this Manual
PDF (US Ltr) - 2.4Mb
PDF (A4) - 2.4Mb
HTML Download (TGZ) - 250.9Kb
HTML Download (Zip) - 258.4Kb


MySQL PHP API  /  ...  /  CollectionModify::limit

5.9.6 CollectionModify::limit

Copyright 1997-2019 the PHP Documentation Group.

  • CollectionModify::limit

    Limit number of modified documents

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::limit(integer rows);

Limit the number of documents modified by this operation. Optionally combine with skip() to define an offset value.

Parameters

rows

The maximum number of documents to modify.

Return Values

A CollectionModify object.

Examples

Example 5.44 mysql_xdevapi\CollectionModify::limit example

<?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());
?>

The above example will output something similar to:


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
        )
)