Loading TOC...

dls.documentInsertAndManage

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

Summary

This function inserts a document into the database and places the document under management.

Parameters
$uri The URI of the document.
$deep Specifies whether to manage this document as well as any documents for which this document has XInclude references to. Specify true to manage all XInclude references or false to not manage any included documents. The default is false.
$doc The contents of the document (root node).
$annotation Any comments you want to add to the properties.
$permissions Security permission elements corresponding to the permissions for the 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, the current user's default permissions are applied. The default value used for $permissions can be obtained by calling xdmp.defaultPermissions . 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 XDMP-MUSTHAVEUPDATE exception.
$collections The collection URIs for collections to which this document belongs. 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 xdmp.defaultCollections.
$quality 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.
$forest-ids 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 specified 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.

Example

// Inserts 'baz.json' into the database and places the document under management.

const dls = require('/MarkLogic/dls');

var contents = {
  title: "Baz Goes to the Disco",
  chapter1: "Baz wakes up"
};   

declareUpdate();
dls.documentInsertAndManage(
  "/foo/bar/baz.json",
   true,
   contents);
   

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