Add the Documents
For our simple example, we will use three documents, two in XML and one in JSON. Use the Query Console to insert these documents into the Documents database, along with read and update permissions for els-user-1
and els-user-2
:
(: run this against the Documents database :) xquery version "1.0-ml"; import module namespace sec="http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy"; xdmp:document-insert("test1.xml", <root> <bar baz="1" attr="test">abc</bar> <bar baz="2">def</bar> <bar attr="test1">ghi</bar> </root>, (xdmp:permission("els-role-1", "read"), xdmp:permission("els-role-2", "read"), xdmp:permission("els-role-1", "update"), xdmp:permission("els-role-2", "update"))) , xdmp:document-insert("test2.xml", <root> <reg expr="this is a string">1</reg> <reg>2</reg> </root>, (xdmp:permission("els-role-1", "read"), xdmp:permission("els-role-2", "read"), xdmp:permission("els-role-1", "update"), xdmp:permission("els-role-2", "update"))) , xdmp:document-insert("test1.json", object-node { "foo" : 1, "bar" : "2", "baz" : object-node {"bar" : array-node {3,4}, "test" : 5} }, (xdmp:permission("els-role-1", "read"), xdmp:permission("els-role-2", "read"), xdmp:permission("els-role-1", "update"), xdmp:permission("els-role-2", "update")))
The code example adds permissions to the documents for els-role-1
and els-role-2
while inserting them into the database.