Loading TOC...

xdmp:document-add-collections

xdmp:document-add-collections(
   $uri as xs:string,
   $collections as xs:string*
) as empty-sequence()

Summary

Adds the named document to the given 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.

Parameters
$uri The document URI.
$collections A set of collection URIs.

Required Privileges

If adding an unprotected collection to a document, the unprotected-collections privilege (http://marklogic.com/xdmp/privileges/unprotected-collections) is needed; if adding a protected collection, the user must have either permissions to update the collection or the any-collection privilege (http://marklogic.com/xdmp/privileges/any-collection).

Example

xdmp:document-add-collections(
    "/example.xml",
    ("http://examples.com", "http://marklogic.com"))

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

Comments

The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.
  • If the above example gives you an error XDMP-DOCNOTFOUND, make sure to create collection ("http://examples.com") first. It can be done implicitly: xdmp:document-insert("http://example1.xml", <root>example1 data</root>,(), ("http://examples.com"));
  • Hi, how can i resolve this exception saying "Collection lexicon not enabled". Where or how will I enable collection lexicons? thanks a lot
  • I noticed that I can add collections to a managed document using this function. Shouldn't I be required to use dls:document-add-collections instead for managed documents?
    • Hello Abraham, This is a lower level function and access to saving a document to a specific collection will be based upon the priv of the user executing (either function) To restrict access to a specific collection you probably want to investigate protected collection security http://docs.marklogic.com/guide/search-dev/collections#id_32054 if you think default behavior of DLS is to setup protected collections, then thats probably an RFE (you can raise via support portal).