mysql_xdevapi\Collection
PHP Manual

Collection::modify

(No version information available, might only be in Git)

Collection::modifyModify collection documents

说明

public mysql_xdevapi\CollectionModify mysql_xdevapi\Collection::modify ( string $search_condition )

Modify collections that meet specific search conditions. Multiple operations are allowed, and parameter binding is supported.

参数

search_condition

Must be a valid SQL expression used to match the documents to modify. This expression might be as simple as TRUE, which matches all documents, or it might use functions and operators such as 'CAST(_id AS SIGNED) >= 10', 'age MOD 2 = 0 OR age MOD 3 = 0', or '_id IN ["2","5","7","10"]'.

返回值

If the operation is not executed, then the function will return a Modify object that can be used to add additional modify operations.

If the modify operation is executed, then the returned object will contain the result of the operation.

范例

Example #1 mysql_xdevapi\Collection::modify() example

<?php
// Assuming $coll is a valid Collection object

// To all the documents with the 'job' field like 'Programmatore' or 'Cantante' append two new jobs: Volontario and Tassinaro
$coll->modify("job in ('Programmatore', 'Cantante')")->arrayAppend('job''Volontario')->arrayAppend('job''Tassinaro')->execute();

// Remove the 'age' field from all the docs with 'ordinal' between 1 and 9
$coll->modify('ordinal >= 1 and ordinal <= 9')->unset(['age'])->execute();

/*
 The modify operation is split in two lines, the object returned by a not executed 'modify'
 holds the state of the current modify (it might be executed later)
*/
$obj $coll->modify('age > :age1 and age < :age2')->bind(['age1' => 25'age2' => 40]);
$data $obj->sort(['_id desc'])->limit(2)->replace('job''Disoccupato')->execute();
?>

mysql_xdevapi\Collection
PHP Manual