JS/SQL also provides possibility to replace the entire document with REPLACE statement.

The Replace command replaces an existing document, or if a document with the specified ID does not exist, the Replace command returns an error.

REPLACE WITH JSON VALUE example:

REPLACE product["34940855"] WITH JSON VALUE {
  "name": "Schwinn S32 Full Suspension Mountain Bike",
  "image_url": "schwinn_s32.jpeg",
  "description": "Information is not available",
  "color": "black",
  "price": 459.16,
  "availability": "Data not available"
}

 REPLACE WITH XML VALUE example:

REPLACE product["34940855"] WITH XML VALUE
<document>
<name>Schwinn S32 Full Suspension Mountain Bike</name>
<image_url>schwinn_s32.jpeg</image_url>
<description>Information is not available</description>
<color>black</color>
<price>459.16</price>
<availability>Data not available</availability>
</document>

Note, that XML document should have opening and closing "root" tag, as in example above - <document>.

Possible errors in REPLACE response:

Error code
Description
2824

Requested document does not exist.

2433

Document ID is not set or is empty.

2245

Cannot parse JS/SQL query.
This happens, when request syntax is incorrect, for example ID is not quoted.