MongoDB\Driver\BulkWriteCommand::updateOne

(mongodb >=2.1.0)

MongoDB\Driver\BulkWriteCommand::updateOne — Add an updateOne operation

Descrizione

public function MongoDB\Driver\BulkWriteCommand::updateOne(
    string $namespace,
    array|object $filter,
    array|object $update,
    ?array $options = null
): void

Add an updateOne operation to the MongoDB\Driver\BulkWriteCommand. The first document matching filter in the collection identified by namespace will be updated.

Elenco dei parametri

namespace (string)

Un namespace completamente qualificato (ad es. "databaseName.collectionName").

filter (array|object)

Il » predicato della query. Un predicato vuoto corrisponderà a tutti i documenti della collezione.

Nota:

Nel valutare i criteri della query, MongoDB confronta tipi e valori secondo le proprie » regole di confronto per i tipi BSON, che differiscono dalle regole di confronto e di type juggling di PHP. Quando si cerca la corrispondenza con un tipo BSON speciale, i criteri della query devono usare la rispettiva classe BSON (ad es. usare MongoDB\BSON\ObjectId per trovare un » ObjectId).

update (array|object)

A document containing either update operators (e.g. $set) or an » aggregation pipeline.

options

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 La » collation consente agli utenti di specificare regole specifiche della lingua per il confronto tra stringhe, come le regole per maiuscole/minuscole e per gli accenti. Quando si specifica la collation, il campo "locale" è obbligatorio; tutti gli altri campi della collation sono opzionali. Per le descrizioni dei campi, si consulti » Collation Document. Se la collation non è specificata ma la collezione ha una collation predefinita, l'operazione usa la collation specificata per la collezione. Se non è specificata alcuna collation né per la collezione né per l'operazione, MongoDB usa per i confronti tra stringhe il semplice confronto binario utilizzato nelle versioni precedenti. Questa opzione è disponibile in MongoDB 3.4+ e causerà un'eccezione al momento dell'esecuzione se specificata per una versione del server precedente.
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

Valori restituiti

Nessun valore viene restituito.

Errori/Eccezioni

Esempi

Example #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);

?>

Vedere anche:

User Contributed Notes

There are no user contributed notes for this page.
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top