I need to update the permission on all existing documents, can you help me with XQuery code?
There are several methods available to adjust document permissions:
An example of how you could change the permissions on all of the documents:
let $permissions := (
xdmp:permission("development", "update"),
xdmp:permission("qa", "read")
)
for $uri in cts:uris("", (), cts:true-query())
return xdmp:document-set-permissions($uri, $permissions)
Depending upon the size of your database and how many documents you need to update, you may need to look into using xdmp:spawn-function()
:
let $permissions := (
xdmp:permission("development", "update"),
xdmp:permission("qa", "read")
)
for $uri in cts:uris("", (), cts:true-query())
return
xdmp:spawn-function(function() {
xdmp:document-set-permissions($uri, $permissions)
})
Or using a tool such as CoRB to perform those updates, which can spread the load across the cluster and avoid a backlog on the task server (spawning puts work onto the task server queue of the host executing the query). Plus, you can control the thread count to better adjust the rate and throughput of the job.
Note: Using xdmp:document-set-permissions()
will replace any existing permissions with whatever you specify. If you want to retain the existing permissions and only add new ones, then use xdmp:document-add-permissions()
.