
temporal:document-insert( $temporal-collection as xs:string, $uri as xs:string, $root as node(), [$options as (element()|map:map)?] ) as empty-sequence()
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.)
An exception is thrown if $temporal-collection is not
temporal or $collection includes temporal collection(s).
| Parameters | |
|---|---|
| temporal-collection | The URI for the protected temporal collection in which the document is to belong. This must have been previously created by the temporal:collection-create function. All versions of the temporal document will be associated with this temporal collection. |
| uri | 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. |
| root | The root node of the document. The root node can be one of XML format, JSON format, binary (BLOB) format, or text (CLOB) format. |
| options |
Options with which to customize this operation. You
can specify options as either an options XML element
in the "xdmp:document-insert" namespace, or as a map:map.
The options names below are XML element localnames. When using a map,
replace the hyphens with camel casing. For example, "an-option"
becomes "anOption" when used as a map:map key.
This function supports the following options, plus the options from the
xdmp:http-get
function.
|
xquery version "1.0-ml";
import module namespace temporal = "http://marklogic.com/xdmp/temporal"
at "/MarkLogic/temporal.xqy";
let $root :=
<tempdoc>
<content>v1-content here</content>
</tempdoc>
let $options :=
<options xmlns="xdmp:document-insert">
<metadata>
<map:map xmlns:map="http://marklogic.com/xdmp/map">
<map:entry key="validStart">
<map:value>2014-04-03T11:00:00</map:value>
</map:entry>
<map:entry key="validEnd">
<map:value>2014-04-03T16:00:00</map:value>
</map:entry>
</map:map>
</metadata>
</options>
return
temporal:document-insert("kool", "koolorder.xml", $root, $options)