@@ -335,34 +335,46 @@ this.patchDocument = function (documentLink, patchSpec, options, callback) {
335
335
> [! NOTE ]
336
336
> Find the definition of `validateOptionsAndCallback ` in the [.js DocDbWrapperScript ](https :// github.com/Azure/azure-cosmosdb-js-server/blob/1dbe69893d09a5da29328c14ec087ef168038009/utils/DocDbWrapperScript.js#L289) on GitHub.
337
337
338
- Sample parameter for patch operation :
338
+ Sample stored procedure for patch operation :
339
339
340
340
```javascript
341
- function () {
341
+ function patchDemo () {
342
342
var doc = {
343
- " id" : " exampleDoc" ,
344
- " field1" : {
345
- " field2" : 10 ,
346
- " field3" : 20
347
- }
348
- };
349
- var isAccepted = __ .createDocument (__ .getSelfLink (), doc , (err , doc ) => {
350
- if (err ) throw err ;
351
- var patchSpec = [
352
- {" op" : " add" , " path" : " /field1/field2" , " value" : 20 },
353
- {" op" : " remove" , " path" : " /field1/field3" }
354
- ];
355
- isAccepted = __ .patchDocument (doc ._self , patchSpec , (err , doc ) => {
356
- if (err ) throw err ;
357
- else {
358
- getContext ().getResponse ().setBody (docPatched );
359
- }
360
- }
361
- }
362
- if (! isAccepted ) throw new Error (" patch was't accepted" )
363
- }
364
- }
365
- if (! isAccepted ) throw new Error (" create wasn't accepted" )
343
+ " id" : " exampleDoc" ,
344
+ " fields" : {
345
+ " field1" : " exampleString" ,
346
+ " field2" : 20 ,
347
+ " field3" : 40
348
+ }
349
+ };
350
+
351
+ var isAccepted = __ .createDocument (__ .getSelfLink (), doc , (err , doc ) => {
352
+ if (err ) {
353
+ throw err ;
354
+ }
355
+ else {
356
+ getContext ().getResponse ().setBody (" Example document successfully created." );
357
+
358
+ var patchSpec = [
359
+ { " op" : " add" , " path" : " /fields/field1" , " value" : " newExampleString" },
360
+ { " op" : " remove" , " path" : " /fields/field2" },
361
+ { " op" : " incr" , " path" : " /fields/field3" , " value" : 10 }
362
+ ];
363
+
364
+ var isAccepted = __ .patchDocument (doc ._self , patchSpec , (err , doc ) => {
365
+ if (err ) {
366
+ throw err ;
367
+ }
368
+ else {
369
+ getContext ().getResponse ().appendBody (" Example document successfully patched." );
370
+ }
371
+ });
372
+
373
+ if (! isAccepted ) throw new Error (" Patch wasn't accepted" );
374
+ }
375
+ });
376
+
377
+ if (! isAccepted ) throw new Error (" Create wasn't accepted." );
366
378
}
367
379
```
368
380
0 commit comments