Loading TOC...

dls.documentCheckoutUpdateCheckin

dls.documentCheckoutUpdateCheckin(
   uri as String,
   doc as Node,
   annotation as Sequence,
   retain-history as Boolean,
   [permissions as Sequence],
   [collections as String[]],
   [quality as Number?],
   [forest-ids as (Number|String)[]]
) as Sequence

Summary

This function allows you to checkout, update, and checkin a managed document in a single transaction.

Parameters
uri The URI of the document to be updated.
doc The new contents of the document.
annotation Any comments you want to add to the new versions of the documents.
retain-history Determines whether or not to retain the document's properties fragment in the database. Set to true to retain the original document's properties in order to track when the document was updated and by whom. Otherwise, set to false.
permissions The permissions to be set on the updated document. When run in an XQuery context, the permissions are a sequence of XML elements (sec:permission). When importing this module into a Server-Side JavaScript context, the permissions are an array of Objects. If not supplied, default permissions are applied. The default value used for this parameter can be obtained by calling xdmp:default-permissions. A document that is updated by a non-admin user (that is, by any user who does not have the admin role) must have at least one update permission.
collections The collection URIs for the collections to which the updated document is to belong. If not supplied, the document maintains its current collections. For each collection that is protected, you must have permissions to update that collection or have the any-collection privilege. For each unprotected collection, you must have the unprotected-collections privilege. The default value used for this parameter can be obtained by calling xdmp:default-collections.
quality Specifies the quality of the updated document. A positive value increases the relevance score of the document in text search functions. The converse is true for a negative value. The default value is 0.
forest-ids Specifies the ID of the forest in which the updated document is inserted. If this parameter is not specified, the updated document will remain in the original document's forest. If no such forest exists or if no such forest is attached to the context database, an error is raised. If multiple forests are specified, the document is inserted into one of the specified forests. If the document exists and the forest in which it is stored is set to delete-only, then you must set this parameter to include one or more forests that allow updates, otherwise an exception is thrown.

Example

  xquery version "1.0-ml";

  import module namespace dls = "http://marklogic.com/xdmp/dls" 
      at "/MarkLogic/dls.xqy";

  let $bazbook :=  
  <BOOK>
    <TITLE>Baz Goes to the Disco</TITLE>
    <CHAPTER1>
      <TITLE>Baz Wakes Up</TITLE>
      <PARA>
        Baz woke up this afternoon to the sound of James Brown.  Soon
        Baz was feeling a little funky, so he put on his cleanest
        propeller hat and headed out in search of a Disco.
      </PARA>
    </CHAPTER1>
  </BOOK> 
      
  return
    dls:document-checkout-update-checkin(
	"/foo/bar/baz.xml",
	$bazbook,
	"Changed the title from Baz Feelin' Funky",
	fn:true())
  
  (: Checks out 'baz.xml', updates the content, and checks it back in. :)
   

Example

/* Checks out 'baz.json', updates the content, and checks it back in. */
const dls = require('/MarkLogic/dls');

const bazbook = {
  title: "Baz Goes to the Disco",
  chapter1: "Baz wakes up",
  para: "Baz woke up this afternoon to the sound of James Brown. Soon Baz was feeling a \
            little funky, so he put on his cleanest \
              propeller hat and headed out in search of a Disco."
};    

declareUpdate();
dls.documentCheckoutUpdateCheckin(
  '/foo/bar/baz.json',
  bazbook,
  "Changed the title from Baz Feelin' Funky",
  true);
   

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.