Oihana PHP Arango

aqlUpdate.php

Table of Contents

Functions

aqlUpdate()  : string
Partially modifies a document with the given attributes, by adding new and updating existing attributes.

Functions

aqlUpdate()

Partially modifies a document with the given attributes, by adding new and updating existing attributes.

aqlUpdate([ReplaceOptions|null, with?: string|null} $init = [] ][, string $operation = Operation::UPDATE ]) : string

Basic Syntax:*

UPDATE `document` IN `collection`
UPDATE `keyExpression` WITH `document` IN `collection`
Parameters
$init : ReplaceOptions|null, with?: string|null} = []

Initial options for the UPDATE or REPLACE statement, with the keys:

  • 'collection' : The collection in which the document is updated, written verbatim (default @@collection).
  • 'doc' : The document expression to update (UPDATE <doc> IN …), used when 'with' is absent (default doc).
  • 'key' : The key expression that 'with' applies to (UPDATE <key> WITH …), used with 'with' only (default doc).
  • 'options' : The default 'options' expression definition
  • 'with' : The document of attributes to apply to 'key' (UPDATE <key> WITH <with> IN …). It is not the AQL WITH collections clause.

'doc', 'key' and 'with' are written verbatim : build a document with aqlDocument(), which takes the 'rawKeys' / 'rawValues' / 'useSpace' options. This function reads none of them, and a PHP array passed here is not formatted.

$operation : string = Operation::UPDATE

The AQL operation to perform. Must be either Operation::UPDATE (default) or Operation::REPLACE.

If the "REPLACE" operation is used, see the replace method.

Tags
throws
ReflectionException

If options serialization or internal reflection fails.

Examples**

// 1. Basic UPDATE of a document expression:
echo aqlUpdate
([
   'collection' => 'users',
   'doc'        => aqlDocument( [ 'name' => 'John' ] )
]);
// UPDATE {name:'John'} IN users

// 2. UPDATE using a custom document expression:
echo aqlUpdate
([
   'collection' => 'products',
   'doc'        => '{ price: 99.99 }'
]);
// UPDATE { price: 99.99 } IN products

// 3. REPLACE instead of UPDATE:
echo aqlUpdate
([
   'collection' => 'profiles',
   'doc'        => aqlDocument( [ 'name' => 'Marc', 'age' => 42 ] )
] , Operation::REPLACE ) ;
// REPLACE {name:'Marc',age:42} IN profiles

// 4. UPDATE with options array (doc):
echo aqlUpdate
([
   'collection' => 'events',
   'doc'        => 'doc',
   'options'    =>
   [
      'ignoreRevs' => true,
      'keepNull'   => false
   ]
]);
// UPDATE doc IN events OPTIONS {"ignoreRevs":true,"keepNull":false}

// 5. UPDATE with UpdateOptions object (doc):
echo aqlUpdate
([
   'collection' => 'products',
   'doc'        => aqlDocument( [ 'price' => 42 ] ),
   'options'    => new UpdateOptions(['mergeObjects' => true])
]);
// UPDATE {price:42} IN products OPTIONS {"mergeObjects":true}

// 6. UPDATE using a key and WITH (no doc):
echo aqlUpdate
([
   'collection' => 'orders',
   'key'        => betweenQuotes('my_key'),
   'with'       => aqlDocument( [ 'name' => 'eka', 'age' => 48 ] )
]);
// UPDATE 'my_key' WITH {name:'eka',age:48} IN orders

// 7. UPDATE using a key in doc and WITH (no doc expression):
echo aqlUpdate
([
   'collection' => 'orders',
   'key'        => key('my_key', 'doc'),
   'with'       => aqlDocument( [ 'name' => 'eka', 'age' => 48 ] )
]);
// UPDATE doc.my_key WITH {name:'eka',age:48} IN orders

// 8. WITH without a key applies to the loop variable doc:
echo aqlUpdate
([
   'collection' => 'orders',
   'with'       => aqlDocument( [ 'status' => 'shipped' ] )
]);
// UPDATE doc WITH {status:'shipped'} IN orders
see
https://docs.arangodb.com/stable/aql/high-level-operations/update
UpdateOptions
author

Marc Alcaraz

since
1.0.0
Return values
string
On this page

Search results