@@ -18,7 +18,7 @@ var exutil = require('./example-util.js');
1818//a real application would require without the 'exutil.' namespace
1919var marklogic = exutil . require ( 'marklogic' ) ;
2020
21- var p = marklogic . patchBuilder ;
21+ var pb = marklogic . patchBuilder ;
2222
2323var dbAdmin = marklogic . createDatabaseClient ( exutil . restAdminConnection ) ;
2424
@@ -28,48 +28,48 @@ var timestamp = (new Date()).toISOString();
2828
2929var uri = '/countries/uv.json' ;
3030var operations = [
31- p . pathLanguage ( 'jsonpath' ) ,
32- p . replaceInsert ( '$.timestamp' , '$.name' , 'after' , timestamp )
31+ pb . pathLanguage ( 'jsonpath' ) ,
32+ pb . replaceInsert ( '$.timestamp' , '$.name' , 'after' , timestamp )
3333 ] ;
3434
3535console . log ( 'configure the server to enforce optimistic locking' ) ;
3636// a one-time administrative action
3737dbAdmin . config . serverprops . write ( {
3838 'update-policy' : 'version-required'
39- } ) .
40- result ( function ( response ) {
39+ } )
40+ . result ( function ( response ) {
4141 console . log (
4242 'try to update a value in the content to ' +
4343 timestamp + '\n without passing the document version id' ) ;
4444 db . documents . patch ( {
4545 uri : uri ,
4646 operations : operations
4747 // 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' ) ;
5454
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 ) {
5858 console . log (
5959 'try to update the document passing the version id ' + document . versionId ) ;
6060 return db . documents . patch ( {
6161 uri : uri ,
6262 operations : operations ,
6363 versionId : document . versionId
6464 } ) . result ( ) ;
65- } ) .
66- then ( function ( response ) {
65+ } )
66+ . then ( function ( response ) {
6767 console . log ( 'update succeeded with the version id' ) ;
6868
6969 console . log ( 'get the new version id for the updated document' ) ;
7070 return db . documents . read ( uri ) . result ( ) ;
71- } ) .
72- then ( function ( documents ) {
71+ } )
72+ . then ( function ( documents ) {
7373 var document = documents [ 0 ] ;
7474 console . log (
7575 'the document has the new version id ' + document . versionId +
@@ -81,19 +81,21 @@ dbAdmin.config.serverprops.write({
8181 return dbAdmin . config . serverprops . write ( {
8282 'update-policy' : 'merge-metadata'
8383 } ) . result ( ) ;
84- } ) .
85- then ( function ( response ) {
86- console . log ( 'done' ) ;
84+ } )
85+ . then ( function ( response ) {
86+ console . log ( 'done' ) ;
8787
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 ) ) ;
9192
92- exutil . failed ( ) ;
93- } ) ;
93+ exutil . failed ( ) ;
94+ } ) ;
9495 } ) ;
95- } , function ( error ) {
96+ } )
97+ . catch ( function ( error ) {
9698 console . log ( JSON . stringify ( error ) ) ;
9799
98100 exutil . failed ( ) ;
99- } ) ;
101+ } ) ;
0 commit comments