<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/temporal.documentInsert.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>temporal.documentInsert</api:function-name><api:suggest>temporal.documentinsert</api:suggest><api:suggest>temporal</api:suggest><api:suggest>documentinsert</api:suggest><api:function-link mode="xquery" fullname="temporal:document-insert">/apidoc/8.0/temporal:document-insert.xml</api:function-link><api:function mode="javascript" name="documentInsert" lib="temporal" category="Temporal" hidden="false" bucket="MarkLogic Built-In Functions" prefix="temporal" namespace="http://marklogic.com/xdmp/temporal" fullname="temporal.documentInsert"><api:summary>
  This function inserts a document into the database and stores it as a 
  temporal document.  The document will belong to the specified temporal 
  collection to ensure that it can only be updated or deleted using the 
  temporal functions.  If a temporal document already exists at the 
  specified URI, this function performs an update instead of
  an insert.  (Note that updates on temporal documents mean that a new 
  document is created
  in the temporal collection with a different time period.)
  <p xmlns="http://www.w3.org/1999/xhtml">
  An exception is thrown if <code>$temporal-collection</code> is not
  temporal or <code>$collection</code> includes temporal collection(s).
  </p>
  </api:summary><api:params><api:param name="temporal-collection" type="xs:string"><api:param-description>
    The URI for the protected temporal collection in which the document is 
    to belong.  This must have been previously created by the 
    <code xmlns="http://www.w3.org/1999/xhtml">temporal:collection-create</code> function.
    All versions of the temporal document will be associated with this 
    temporal collection.
    </api:param-description><api:param-name>temporal-collection</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="uri" type="xs:string"><api:param-description>
    The URI to be used to identify the document in the database.  If 
    the document is not the latest version, a suffix will be concatenated 
    to the document URI with a dot as the new URI of the document.
    </api:param-description><api:param-name>uri</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="root" type="node()"><api:param-description>
    The root node of the document. The root node can be one of XML format, 
    JSON format, binary (BLOB) format, or text (CLOB) format.
    </api:param-description><api:param-name>root</api:param-name><api:param-type>Node</api:param-type></api:param><api:param class="javascript" name="permissions" type="Object[]" optional="true"><api:param-description>
    Security permission objects corresponding to the permissions for the 
    document.  The permissions specified only apply to the latest 
    document versions created in this operation; previous versions of the 
    documents will retain their previous permissions.
    If not supplied, the current user's default permissions are applied. 
    The default value used for permissions can be obtained by calling 
    <code xmlns="http://www.w3.org/1999/xhtml">xdmp.defaultPermissions()</code>.  A document that is created by 
    a non-admin user (that is, by any user who does not have the admin role)
    must have at least one update permission, otherwise the creation will 
    throw an <code xmlns="http://www.w3.org/1999/xhtml">XDMP-MUSTHAVEUPDATE</code> exception.
    </api:param-description><api:param-name>permissions</api:param-name><api:param-type>Object[]</api:param-type></api:param><api:param name="collections" type="xs:string*" optional="true"><api:param-description>
    The collection URIs for any additional, non-temporal collections the 
    document is to belong to.  If not supplied, the document is added to the 
    current user's default collections. For each collection that is protected, 
    the user must have permissions to update that collection or have
    the any-collection privilege. For each unprotected collection, the user 
    must have the unprotected-collections privilege. The default value used 
    for $collections can be obtained
    by calling <code xmlns="http://www.w3.org/1999/xhtml">xdmp:default-collections()</code>.
    The collections specified only apply to the latest 
    document versions created in this operation; previous versions of the 
    documents will retain their previous collections.
    </api:param-description><api:param-name>collections</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="quality" type="xs:int?" optional="true"><api:param-description>
    The quality of this 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.
    </api:param-description><api:param-name>quality</api:param-name><api:param-type>xs.int?</api:param-type></api:param><api:param name="forest-ids" type="xs:unsignedLong*" optional="true"><api:param-description>
     Specifies the ID of the forest in which this document is inserted. If 
     the document already exists in the database and if $forest-ids is not 
     specified, it will remain in its existing 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 specifed forests.  If the document exists and 
     the forest in which it is stored is set to delete-only, then you must
     set $forest-ids to include one or more forests that allow updates, 
     otherwise an exception is thrown.
     <p xmlns="http://www.w3.org/1999/xhtml">
     If you have local disk failover enabled, specify the ID of the master 
     forest. In the event of a failover, MarkLogic server will automatically 
     redirect documents to the replica forest. Specify the ID of the replica 
     forest will result in a "forest not in database" error.
     </p>
    </api:param-description><api:param-name>forest-ids</api:param-name><api:param-type>String[]</api:param-type></api:param></api:params><api:return>null</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
declareUpdate();

var root =
{
   "systemStart" : "2001-01-01T00:00:00Z",
   "systemEnd" : "2001-01-01T00:00:00Z",
   "validStart" : "2014-06-03T14:13:05.472585-07:00",
   "validEnd" : "9999-12-31T23:59:59.99Z",
   "content" : "v1-content here"
}

temporal.documentInsert( "temporalCollection", "doc.json", root )
</pre></api:example></api:function></api:function-page>