1

Will elaborate - when I execute the following command :

let $value := xdmp:forest-status(
                xdmp:forest-open-replica(
                  xdmp:database-forests(xdmp:database("Documents"))))
return $value

Above query returns a lot of information about the database "Documents" forest, like - forest-id, host-id, etc.

I only require that it should return only the "state" of my forest. How do I do that?

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Aviator
  • 543
  • 1
  • 4
  • 10

1 Answers1

4

Use XPath to select what you want to return.

let $value := xdmp:forest-status(
                xdmp:forest-open-replica(
                  xdmp:database-forests(xdmp:database("Documents"))))
return $value/*:state/text()

Also, no need for a FLWOR you could make it a one-liner:

xdmp:forest-status(
  xdmp:forest-open-replica(
    xdmp:database-forests(xdmp:database("Documents"))))/*:state/text()

Or you may find that using the arrow operator makes things easier to read instead of nested function calls and tons of parenthesis wrapping them:

(xdmp:database("Documents")
  => xdmp:database-forests()
  => xdmp:forest-open-replica()
  => xdmp:forest-status()
)/*:state/text()

The XML elements in the response are in the http://marklogic.com/xdmp/status/forest namespace. So, you would either need to declare the namespace (i.e. declare namespace f = "http://marklogic.com/xdmp/status/forest";) and use the prefix in your XPath (i.e. f:state), or just use the wildcard as I have done *:state

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147