The Admin module is an XQuery library module that allows you to script administrative tasks that you otherwise would need the Admin Interface to perform. Most functions in this library perform adminstrative tasks and therefore require the user who runs the XQuery program to have the Admin role.
Many of these functions provide new configuration information. In most cases, you must save the configuration (with admin:save-configuration, for example) in the same statement that you use the functions in order for them to take effect.
admin:save-configuration
To use the Admin module as part of your own XQuery module, include the following line in your XQuery prolog:
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy" ;
The library namespace prefix admin is not predefined in the server.
admin
http://marklogic.com/xdmp/privileges/admin-module-read
xquery version "1.0-ml"; import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; let $config := admin:get-configuration() return admin:database-get-range-element-indexes($config, xdmp:database("Documents") ) => The xml for any element range indexes in the "Documents" database, for example: <range-element-index xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://marklogic.com/xdmp/database"> <scalar-type>date</scalar-type> <collation/> <namespace-uri>mynamespace</namespace-uri> <localname>myelementname</localname> <range-value-positions>false</range-value-positions> </range-element-index>
xdmp:host()
(: This query restarts all hosts in the cluster. Note that it will restart the host in which the query is run, too. :) xquery version "1.0-ml"; import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; declare namespace host="http://marklogic.com/xdmp/status/host"; let $hostids := for $id in xdmp:host-status(xdmp:host()) /host:hosts//host:host/host:host-id return fn:data($id) return admin:restart-hosts($hostids)
admin:save-configuration-without-restart
http://marklogic.com/xdmp/privileges/admin-module-write
xquery version "1.0-ml"; import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; let $config := admin:get-configuration() let $spec := admin:forest-set-enabled($config, xdmp:forest("myForest"), fn:true() ) return admin:save-configuration($spec)
xquery version "1.0-ml"; import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; let $config := admin:get-configuration() let $spec := admin:forest-set-enabled($config, xdmp:forest("myForest"), fn:true() ) return admin:save-configuration-without-restart($spec)