<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.documentAssign.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.documentAssign</api:function-name><api:suggest>xdmp.documentassign</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>documentassign</api:suggest><api:function-link mode="xquery" fullname="xdmp:document-assign">/apidoc/8.0/xdmp:document-assign.xml</api:function-link><api:function mode="javascript" name="documentAssign" type="builtin" lib="xdmp" category="UpdateBuiltins" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.documentAssign"><api:summary>
  <p xmlns="http://www.w3.org/1999/xhtml">
  Assign a document URI to a forest index,
  using the same algorithm as <code>xdmp:document-insert</code>.
  The return value will be a positive integer
  from 1 to <code>$forest-count</code>.
  </p>
  <p xmlns="http://www.w3.org/1999/xhtml">
  This function does not insert or update the document;
  instead, it returns the index of the forest
  to which the document URI would be assigned
  if it were inserted as a new document.
  In order to match the document to the correct forest,
  use the list of forest-IDs as returned by <code>xdmp:database-forests</code>.
  </p>
  <p xmlns="http://www.w3.org/1999/xhtml">
  If the document already exists, this function may not
  return the correct forest for the document. In this case,
  <code>xdmp:document-forest</code> will return the
  correct forest.
  </p>
  <p xmlns="http://www.w3.org/1999/xhtml">
  If "assignment-policy" is specified, this function uses the specified
  policy to calculate the assignment. Otherwise, it uses the assignment
  policy of the context database to calculate the assignment.
  </p>
  <p xmlns="http://www.w3.org/1999/xhtml">
  This function works only with the bucket assignment policy and
  the legacy assignment policy. It reports an error if the statistical
  policy or the range policy is set.
  </p>
  <p xmlns="http://www.w3.org/1999/xhtml">
  Note that, if there are read-only or delete-only forests in a database that
  uses the bucket policy, the application may need to call this function twice
  to get the right assignment. The first call should pass in the total number
  of forests, including the read-only or delete-only ones. If the returned value
  happens to be a read-only or delete-only forest,  the second call should pass
  in the number of forests that excludes the read-only or delete-only ones and
  pass in "legacy" as the third parameter.
  </p>
</api:summary><api:params><api:param name="uri" type="xs:string"><api:param-description>
    The document URI to assign.
  </api:param-description><api:param-name>uri</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="forest-count" type="xs:positiveInteger"><api:param-description>
    Specifies the number of forests from which this document
    may be assigned.
  </api:param-description><api:param-name>forest-count</api:param-name><api:param-type>Number</api:param-type></api:param><api:param name="assignment-policy" type="xs:string" optional="true"><api:param-description>
    Specifies the assignment policy to use. The value must be
    either "legacy" or "bucket".
  </api:param-description><api:param-name>assignment-policy</api:param-name><api:param-type>String</api:param-type></api:param></api:params><api:return>Number</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
xdmp.documentAssign("document-1.xml", 2)
=&gt; 2
</pre></api:example></api:function></api:function-page>