@@ -18,7 +18,7 @@ var exutil = require('./example-util.js');
18
18
//a real application would require without the 'exutil.' namespace
19
19
var marklogic = exutil . require ( 'marklogic' ) ;
20
20
21
- var p = marklogic . patchBuilder ;
21
+ var pb = marklogic . patchBuilder ;
22
22
23
23
var dbAdmin = marklogic . createDatabaseClient ( exutil . restAdminConnection ) ;
24
24
@@ -28,48 +28,48 @@ var timestamp = (new Date()).toISOString();
28
28
29
29
var uri = '/countries/uv.json' ;
30
30
var operations = [
31
- p . pathLanguage ( 'jsonpath' ) ,
32
- p . replaceInsert ( '$.timestamp' , '$.name' , 'after' , timestamp )
31
+ pb . pathLanguage ( 'jsonpath' ) ,
32
+ pb . replaceInsert ( '$.timestamp' , '$.name' , 'after' , timestamp )
33
33
] ;
34
34
35
35
console . log ( 'configure the server to enforce optimistic locking' ) ;
36
36
// a one-time administrative action
37
37
dbAdmin . config . serverprops . write ( {
38
38
'update-policy' : 'version-required'
39
- } ) .
40
- result ( function ( response ) {
39
+ } )
40
+ . result ( function ( response ) {
41
41
console . log (
42
42
'try to update a value in the content to ' +
43
43
timestamp + '\n without passing the document version id' ) ;
44
44
db . documents . patch ( {
45
45
uri : uri ,
46
46
operations : operations
47
47
// versionId not specified
48
- } ) . result (
49
- function ( success ) {
50
- console . log ( 'should never execute' ) ;
51
- } ,
52
- function ( failure ) {
53
- console . log ( 'expected failure for the update without the version id' ) ;
48
+ } )
49
+ . result ( function ( success ) {
50
+ console . log ( 'should never execute' ) ;
51
+ } )
52
+ . catch ( function ( failure ) {
53
+ console . log ( 'expected failure for the update without the version id' ) ;
54
54
55
- console . log ( 'get the current version id for the document' ) ;
56
- db . documents . probe ( uri ) . result ( ) .
57
- then ( function ( document ) {
55
+ console . log ( 'get the current version id for the document' ) ;
56
+ db . documents . probe ( uri )
57
+ . result ( function ( document ) {
58
58
console . log (
59
59
'try to update the document passing the version id ' + document . versionId ) ;
60
60
return db . documents . patch ( {
61
61
uri : uri ,
62
62
operations : operations ,
63
63
versionId : document . versionId
64
64
} ) . result ( ) ;
65
- } ) .
66
- then ( function ( response ) {
65
+ } )
66
+ . then ( function ( response ) {
67
67
console . log ( 'update succeeded with the version id' ) ;
68
68
69
69
console . log ( 'get the new version id for the updated document' ) ;
70
70
return db . documents . read ( uri ) . result ( ) ;
71
- } ) .
72
- then ( function ( documents ) {
71
+ } )
72
+ . then ( function ( documents ) {
73
73
var document = documents [ 0 ] ;
74
74
console . log (
75
75
'the document has the new version id ' + document . versionId +
@@ -81,19 +81,21 @@ dbAdmin.config.serverprops.write({
81
81
return dbAdmin . config . serverprops . write ( {
82
82
'update-policy' : 'merge-metadata'
83
83
} ) . result ( ) ;
84
- } ) .
85
- then ( function ( response ) {
86
- console . log ( 'done' ) ;
84
+ } )
85
+ . then ( function ( response ) {
86
+ console . log ( 'done' ) ;
87
87
88
- exutil . succeeded ( ) ;
89
- } , function ( error ) {
90
- console . log ( JSON . stringify ( error ) ) ;
88
+ exutil . succeeded ( ) ;
89
+ } )
90
+ . catch ( function ( error ) {
91
+ console . log ( JSON . stringify ( error ) ) ;
91
92
92
- exutil . failed ( ) ;
93
- } ) ;
93
+ exutil . failed ( ) ;
94
+ } ) ;
94
95
} ) ;
95
- } , function ( error ) {
96
+ } )
97
+ . catch ( function ( error ) {
96
98
console . log ( JSON . stringify ( error ) ) ;
97
99
98
100
exutil . failed ( ) ;
99
- } ) ;
101
+ } ) ;
0 commit comments