I just want to find all document names in a forest.
I know the forest name(ABC) and I need to find all documents in that forest(ABC). My out put should looks like this.
Forest ABC has
A.xml
B.xml
C.xml
and so on...
In order to list all of the URIs from a particular forest, you can use cts:uris()
and specify the forest-id in the 5th parameter:
cts:uris((), (), cts:true-query(), (), xdmp:forest("ABC"))
Your comment suggested that the reason why you are attempting to list all of the URIs from a particular forest was so that you could delete the ones that are duplicates.
The code below could be use to obtain all of the URIs from the specified forest, and then remove them from that forest if they are duplicates.
If you attempt to read the document properties and a XDMP-DBDUPURI exception is thrown, catch that exception and then delete the document in a different transaction from the problem forest.
(: update this with the name of problem forest :)
declare variable $PROBLEM-FOREST := xdmp:forest("ABC");
declare variable $URIS := cts:uris((), (), cts:true-query(), (), $PROBLEM-FOREST);
for $uri in $URIS
return
try {
let $properties := xdmp:document-get-properties($uri, xs:QName("foo"))
return ()
} catch($e) {
if ($e/error:code = "XDMP-DBDUPURI") then
xdmp:invoke-function(
function(){ xdmp:document-delete($uri) },
<options xmlns="xdmp:eval">
<isolation>different-transaction</isolation>
<database>{$PROBLEM-FOREST}</database>
</options>
)
else ()
}
Depending on how many documents are in this forest, you may run into timeout issues. You might consider running this as a CORB job where the forsts URIs are selected in the URIS-MODULE and then each inspection/delete is handled individually in the PROCESS-MODULE.