Query on a database different from the one working on with XQuery

167 views Asked by At

Currently I'm working on an application that is making queries on a given MarkLogic database, the default one as we can say, but to provide same values on the screen I have to check the role of the logged user before displaying. This can be done querying the Security database, the one provided by MarkLogic itself, but I don't know how to explicitly declare on the query that I want to query that particular database instead of the default one. Do you know some command that could help me? Thank you!

1

There are 1 answers

5
wst On BEST ANSWER

You can use eval to query against another database:

xdmp:eval("doc('/docs/mydoc.xml')",  (),
  <options xmlns="xdmp:eval">
    <database>{xdmp:database("otherdb")}</database>
  </options>)

See: https://docs.marklogic.com/xdmp:eval

Also, if you are querying the security database specifically, then instead of xdmp:database you can use xdmp:security-database.