<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.documentLocks.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.documentLocks</api:function-name><api:suggest>xdmp.documentlocks</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>documentlocks</api:suggest><api:function-link mode="xquery" fullname="xdmp:document-locks">/apidoc/8.0/xdmp:document-locks.xml</api:function-link><api:function mode="javascript" name="documentLocks" type="builtin" lib="xdmp" category="Extension" subcategory="Documents, Directories, Properties, and Locks" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.documentLocks"><api:summary>
  Returns the locks for one or more documents or directories.
  Returns the locks for all documents and directories
  in the database if no parameter is given.
</api:summary><api:params><api:param name="uri" type="xs:string*" optional="true"><api:param-description>
    A document URI.
  </api:param-description><api:param-name>uri</api:param-name><api:param-type>String[]</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api:usage>
<p xmlns="http://www.w3.org/1999/xhtml">Note that the locks described here are relatively heavy persistent
document locks for file system emulation through WebDAV, not relatively
light transaction locks for database consistency.</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp.documentLocks("example.xml");
=&gt;
&lt;?xml version="1.0" encoding="ASCII"?&gt;
&lt;lock:lock xmlns:lock="http://marklogic.com/xdmp/lock"&gt;
  &lt;lock:lock-type&gt;write&lt;/lock:lock-type&gt;
  &lt;lock:lock-scope&gt;exclusive&lt;/lock:lock-scope&gt;
  &lt;lock:active-locks&gt;
    &lt;lock:active-lock&gt;
      &lt;lock:depth&gt;0&lt;/lock:depth&gt;
      &lt;lock:owner&gt;
        &lt;DAV:href xmlns:DAV="DAV:"&gt;http://example.com/~user&lt;/DAV:href&gt;
      &lt;/lock:owner&gt;
      &lt;lock:timeout&gt;120&lt;/lock:timeout&gt;
      &lt;lock:lock-token&gt;http://marklogic.com/xdmp/locks/1c267a036b8480c3
      &lt;/lock:lock-token&gt;
      &lt;lock:timestamp&gt;1290136652&lt;/lock:timestamp&gt;
      &lt;sec:user-id xmlns:sec="http://marklogic.com/xdmp/security"&gt;
        893641342095093063&lt;/sec:user-id&gt;
    &lt;/lock:active-lock&gt;
  &lt;/lock:active-locks&gt;
&lt;/lock:lock&gt;
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//   The time is in epoch time, which is seconds from the start
//   of 1970, so this code does a little math on the values in
//   the lock document to figure out how many seconds are left
//   for the lock.  Assumes a lock on /example.json, for example
//   by running the following:
//
//  declareUpdate();
//  xdmp.lockAcquire("/example.json", "exclusive", "0", [], 120);

var lock = xdmp.documentLocks("/example.json").next().value.root;
var lockDuration = new Number;
lockDuration = lock.xpath(
  "/lock:lock/lock:active-locks/lock:active-lock/lock:timeout/fn:data(.)",
  {"lock": "http://marklogic.com/xdmp/lock"}).next().value;
var currentEpochTime =
     fn.round(fn.currentDateTime().toObject().getTime() / 1000) ; 
     // divide by 1000 to convert miliseconds to seconds
var startTime = new Number;
startTime = lock.xpath(
  "/lock:lock/lock:active-locks/lock:active-lock/lock:timestamp/fn:data(.)",
  {"lock": "http://marklogic.com/xdmp/lock"}).next().value;
var endTime = new Number;
endTime = startTime + lockDuration;
var secondsLeft = endTime - currentEpochTime;
var res = [currentEpochTime, endTime, secondsLeft];
res;

=&gt;
1290136837
1290136832
115
</pre></api:example></api:function></api:function-page>