How to construct xquery to retrieve a list of user name and roles name. thanks in advance for any sample xquery code.
You would just need to query the documents in the Security database. As an admin, you can do this by putting the query inside an xdmp:invoke-function()
like so:
xquery version "1.0-ml";
import module namespace sec="http://marklogic.com/xdmp/security" at
"/MarkLogic/security.xqy";
xdmp:invoke-function(function() {
for $user in //sec:user
let $user-name := $user/sec:user-name/text()
let $roles := sec:user-get-roles($user-name)
return
<user>
<user-name>{$user-name}</user-name>
<roles>
{for $role in $roles return <role>{$role}</role>}
</roles>
</user>
},
<options xmlns="xdmp:eval">
<database>{xdmp:security-database()}</database>
</options>)