(无版本信息可用,可能只在 Git 中)
CollectionModify::limit — 限制修改文档数量
限制此操作修改的文档数量。可与 skip() 组合以定义偏移量值。
rows
要修改的最大文档数量。
CollectionModify 对象。
示例 #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 ) )