Hi,

The following should get you started:

xquery version "1.0-ml";
import module "http://marklogic.com/xdmp/security";
   at "/MarkLogic/security.xqy";

for $u in /sec:user
let $n := string($u/sec:user-name)
order by $n
return
   <user>
      <name>{ $n }</name>
      { sec:get-role-names($u/sec:role-ids/sec:role-id)
        ! <role>{ string(.) }</role> }
   </user>

A few comments:

- it has to get evaluated against the Security database (e.g. in QConsole)
- /sec:user returns all users in that database
- for each, you can retrieve its name and role IDs
- you can get rols names from IDs using sec:get-role-names()
- the namespace bound to sec: is used both for element and function names
- pay attention to the use of "{", "}" and "!", and when "string()" is used
- try to get them away to see what happens then

That been said, I am not sure this is the simplest kind of query to learn
XQuery and/or MarkLogic.  I very, very rarely have to retrieve all users
and their roles programmatically (but yes, maybe it can help see how things
are organized).

Note also you need admin privileges to run that query (well, not to run it,
but for it to return the users, or it won't even see them) (well, it's a
bit more complex than "admin privileges", but just use the admin user, or
read the security guide).

Regards,

-- 
Florent Georges
H2O Consulting
http://h2o.consulting/


On 25 April 2017 at 19:11, thichxai wrote:

> I am newbie. How can construct marklogic xquery to get all user name and
> their roles.  Any sample code to learn Marklogic.
>
>
>
> Thanks
>
> Thichxai
>
>
>
>
>
> _______________________________________________
> General mailing list
> [email protected]
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
> --
> <http://developer.marklogic.com/mailman/listinfo/general>
> Florent Georges
> <http://developer.marklogic.com/mailman/listinfo/general>
> http://fgeorges.org/
> http://h2o.consulting/ - New website!
>
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to