(mongodb >=2.1.0)
MongoDB\Driver\BulkWriteCommand::updateOne — Add an updateOne operation
$namespace
,$filter
,$update
,$options
= null
Add an updateOne operation to the
MongoDB\Driver\BulkWriteCommand. The first document
matching filter
in the collection identified by
namespace
will be updated.
namespace
(string)
Повна назва простору імен (напр.
"databaseName.collectionName"
).
filter
(array|object)» Предикат запиту. Порожній предикат відповідає всім документам у колекції.
Зауваження: Під час виконання критеріїв запиту MongoDB порівнює типи та значення за власними » правилами порівняння BSON-типів, що відрізняється від правил порівняння і перетворення типів в PHP. Для вибірки даних спеціальних BSON-типів, критерії запиту повинні використовувати відповідний клас BSON (напр. MongoDB\BSON\ObjectId для вибірки » ObjectId).
update
(array|object)
A document containing either update operators (e.g.
$set
) or an
» aggregation pipeline.
options
Option | Type | Description | Default |
---|---|---|---|
arrayFilters | array |
An array of filter documents that determines which array elements to modify for an update operation on an array field. See » Specify arrayFilters for Array Update Operations in the MongoDB manual for more information. |
|
collation | array|object |
» Зіставлення
дозволяє вказувати специфічні для мови правила порівняння рядків,
як от правила регістру та знаків наголосу. Під час визначення
зіставлень поле Якщо зіставлення не вказано, то використовується стандартне зіставлення для колекції, якщо воно вказано. Якщо ж ні, MongoDB використовує просте двійкове порівняння, яке використовувалося в попередніх версіях для порівняння рядків. Цей параметр доступний у MongoDB 3.4+, тож його застосування у старіших версіях викине виключення під час виконання. |
|
hint | string|array|object |
Index specification. Specify either the index name as a string or the index key pattern. If specified, then the query system will only consider plans using the hinted index. |
|
sort | array|object |
Specify which document the operation updates if the query matches multiple documents. The first document matched by the sort order will be updated. |
|
upsert | bool |
If filter does not match an existing document,
insert a single document. The document will be
created by applying operators in update to any
field values in filter .
|
false |
Не повертає значень.
Приклад #1 MongoDB\Driver\BulkWriteCommand::updateOne() example
<?php
$manager = new MongoDB\Driver\Manager;
$bulk = new MongoDB\Driver\BulkWriteCommand;
$bulk->updateOne('db.coll', ['x' => 1], ['$set' => ['y' => 2]]);
$result = $manager->executeBulkWriteCommand($bulk);
?>