user3916117
user3916117

Reputation: 83

Is there a way to get all database names in MarkLogic server in XQuery?

I want to show all database names in a MarkLogic server. However, the functions that I found are:

admin:database-get-name(database ID)
xdmp:database(database name)
xdmp:database(database ID)

They all require a know piece of information about the database. So is there a way to retrieve all database names without knowing there IDs? or is there a way to retrieve the IDs of all databases in the server?

Upvotes: 2

Views: 695

Answers (1)

Yup. xdmp-databases() with xdmp:database-name()

Long-hand clear example:

xquery version "1.0-ml";
for $db-id in xdmp:databases()
  let $db-name := xdmp:database-name($db-id)
  order by $db-name
  return $db-name

or quick-n-dirty:

xquery version "1.0-ml";
declare option xdmp:mapping "true";

xdmp:database-name(xdmp:databases())

Upvotes: 3

Related Questions