
Time for action – patching a document
You will learn how to patch the document with the ID Orders/A655302
using a patching script that combines the JavaScript and parameters.
- In the Management Studio, select the
Orders
database to be the current database and click on the Patch tab to show the Patch screen. - In the Patch type list, select the Document type.
- In the Document to patch textbox, enter
Orders/A655302
, which is the ID of the document we want to patch, and press Enter. - Click on the Add new Parameter button (the green plus sign to the right of the Parameters section) to add a new parameter.
- Enter
ItemName
for the Name andInk Pen
for the Value. - In the Patch Scripts zone, enter the following JavaScript code snippet:
this.UnitCost = this.UnitCost * 1.15 this.Item = ItemName
- Click on the Test button to test the patch script on the selected document.
- Observe the changes in the After Patch section and verify that the document has new fields value.
- Click on the Patch button to execute the patch scripts to make the changes permanent.
What just happened?
We learned how to patch a document using the Management Studio.
We patched the document with the ID= Orders/A655302
to increase the UnitCost
field value by 15 percent and change the Item
field value from Pen
to Ink Pen
.
In steps 1 to 3, we opened the Management Studio and displayed the Patch screen. Then we entered the ID of the document that we want to patch.
In steps 4 to 6, we added a new parameter with name= ItemName
and value=Ink Pen
and entered the patching script.
In this JavaScript code snippet, in the first line of code, the UnitCost
property value is increased by 15 percent. In the second line, the value of the parameter named ItemName
will be assigned to the Item
property.
In steps 7 and 8, we tested the patching script before applying it and visualized the result. Finally, in step 9, we executed the patch script to make the changes permanent.
Have a go hero – patching the Orders collection
In the previous section, you learned to patch a single document. Suppose in a migration scenario when significant structural changes are required by the consuming application, you need to patch more than one document. Of course, you will not process one document at a time. Try to patch the Orders
collection and increase all Units
values by 10 percent.