A newer version of this documentation is available.

View Latest

UPDATE [Beta]

[This is a beta feature; it’s not for use in production. Production systems can use the existing data service API (key-value API) for data modification.]

UPDATE replaces a document that already exists with updated values.

update:

UPDATE keyspace-ref [use-keys-clause] [set-clause] [unset-clause] [where-clause] [limit-clause] [returning-clause]

set-clause:

SET path = expression [update-for] [ , path = expression [update-for] ]*

update-for:

FOR variable (IN | WITHIN) path  (, variable (IN | WITHIN) path)* [WHEN condition ] END

unset-clause:

UNSET path [update-for] (, path [ update-for ])*

keyspace-ref: Specifies the keyspace for which to update the document.

You can add an optional namespace-name to the keyspace-name in this way:

namespace-name:keyspace-name.

use-keys-clause:Specifies the keys of the data items to be updated. Optional. Keys can be any expression.

set-clause:Specifies the value for an attribute to be changed.

unset-clause: Removes the specified attribute from the document.

update-for: The update for clause uses the FOR statement to iterate over a nested array and SET or UNSET the given attribute for every matching element in the array.

where-clause:Specifies the condition that needs to be met for data to be updated. Optional.

limit-clause:Specifies the greatest number of objects that can be updated. This clause must have a non-negative integer as its upper bound. Optional.

returning-clause:Returns the data you updated as specified in the result_expression.

Example:

The following statement changes the "type" of the product, "odwalla-juice1" to "product-juice".

UPDATE product USE KEYS "odwalla-juice1" SET type = "product-juice" RETURNING product.type

"results": [
        {
            "type": "product-juice"
        }
    ]

This statement removes the "type" attribute from the "product" keyspace for the document with the "odwalla-juice1" key.

UPDATE product USE KEYS "odwalla-juice1" UNSET type RETURNING product.*

"results": [
        {
            "productId": "odwalla-juice1",
            "unitPrice": 5.4
        }
    ]

This statement unsets the "gender" attribute in the "children" array for the document with the key, "dave" in the "tutorial" keyspace.

UPDATE tutorial t USE KEYS "dave" UNSET c.gender FOR c IN children END RETURNING t

"results": [
        {
            "t": {
                "age": 46,
                "children": [
                    {
                        "age": 17,
                        "fname": "Aiden"
                    },
                    {
                        "age": 2,
                        "fname": "Bill"
                    }
                ],
                "email": "dave@gmail.com",
                "fname": "Dave",
                "hobbies": [
                    "golf",
                    "surfing"
                ],
                "lname": "Smith",
                "relation": "friend",
                "title": "Mr.",
                "type": "contact"
            }
        }
    ]