
xdmp.documentInsert( uri as String, root as Node, [options as Object?] ) as null
Inserts a new document into the database if a document with the
specified URI does not already exist. If a document already exists
at the specified URI, the function replaces the content of the existing
document with the specified content (the $root parameter)
as an update operation. In addition to replacing the content,
xdmp:document-insert replaces any permissions, collections,
and quality with the ones specified (or with the default values for these
parameters, if not explicitly specified). Also, if a properties
document exists at the same URI, that properties document (including any
content it contains) is preserved.
| Parameters | |
|---|---|
| uri | The URI of the document to be inserted. |
| root | The root node. The root node can be one of JSON format, XML format, binary (BLOB) format, or text (CLOB) format. |
| options |
Options with which to customize this operation.
This function supports the following options, plus the options from the
xdmp.httpGet
function.
|
If a new document is inserted, the unprotected-uri privilege
(only if the URI is not protected), the any-uri privilege, or an
appropriate URI privilege is also needed. If adding an unprotected
collection to a document, the unprotected-collections privilege
is needed; if adding a protected collection, the user must have either
permissions to update the collection or the
any-collection privilege.
If a document is inserted with the admin user and its default permissions, the document will only be accessible by a user with the admin role as the default permissions of the admin user is empty.
declareUpdate();
xdmp.documentInsert(
'/example.json', {a:'aaa'},
{metadata: {foo:'bar'},
permissions :
[xdmp.permission('app-user', 'read'),
xdmp.permission('app-user', 'update')],
collections : 'http://examples.com'})
declareUpdate();
xdmp.documentInsert(
'/example.json',
{a:'aaa'},
{permissions : xdmp.defaultPermissions(),
collections : xdmp.defaultCollections(),
quality : 10})
// Specify the valid start and end time for a temporal document.
declareUpdate();
xdmp.documentInsert(
'/example.json',
{foo:'new content here'},
{metadata: {'valid-start' : '2014-06-03T14:13:05.472585-07:00',
'valid-end' : '9999-12-31T11:59:59Z'}})
// create a text document
declareUpdate();
var textNode = new NodeBuilder();
textNode.addText('This is a text document');
textNode = textNode.toNode();
xdmp.documentInsert('/text-doc.txt', textNode);
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.