Patch command is used to perform partial document updates without having to load, modify, and save a full document. This is usually useful for updating denormalized data in entities.
{CODE:java patch_1@ClientApi\Commands\Patches\Javascript.java /}
Parameters
{CODE:java scriptedpatchrequest@Common.java /}
Before we will move to the examples, let's look at the methods, objects, and variables available:
| ------ |:------:| ------ |
| __document_id
| variable | Id for current document |
| this
| object | Current document (with metadata) |
| LoadDocument(key)
| method | Allows document loading, increases maximum number of allowed steps in script. See Raven/AdditionalStepsForScriptBasedOnDocumentSize
here. |
| PutDocument(key, data, metadata)
| method | Allows document putting, returns generated key |
| IncreaseNumberOfAllowedStepsBy(number)
| method | Will increase the maximum allowed number of steps in script by given value. Only available if Raven/AllowScriptsToAdjustNumberOfSteps
is set to true
. |
| _
| object | Lo-Dash 4.13.1 |
| trim()
| string.prototype | trims the string e.g. this.FirstName.trim()
|
| output(...)
| method | Allows debug your patch, prints passed messages in output tab |
| indexOf(...)
| Array.prototype | wrapper for _.indexOf |
| filter(...)
| Array.prototype | wrapper for _.filter |
| Map(...)
| Array.prototype | wrapper for _.map |
| Where(...)
| Array.prototype | wrapper for _.filter |
| RemoveWhere(...)
| Array.prototype | wrapper for _.remove returning Array for easier chaining |
| Remove(...)
| Array.prototype | wrapper for _.pull returning Array for easier chaining |
Beside built-in functions, custom ones can be introduced. Please visit this page if you want to know how to add custom functions.
{CODE:java patch_2@ClientApi\Commands\Patches\Javascript.java /}
{CODE:java patch_3@ClientApi\Commands\Patches\Javascript.java /}
{CODE:java patch_4@ClientApi\Commands\Patches\Javascript.java /}
{CODE:java patch_5@ClientApi\Commands\Patches\Javascript.java /}
{CODE:java patch_6@ClientApi\Commands\Patches\Javascript.java /}
{CODE:java patch_7@ClientApi\Commands\Patches\Javascript.java /}
{CODE:java patch_8@ClientApi\Commands\Patches\Javascript.java /}
{CODE:java patch_9@ClientApi\Commands\Patches\Javascript.java /}
{CODE:java patch_1_0@ClientApi\Commands\Patches\Javascript.java /}
{CODE:java patch_1_1@ClientApi\Commands\Patches\Javascript.java /}
{CODE:java patch_1_2@ClientApi\Commands\Patches\Javascript.java /}