Search code examples
marklogic

save uris output on console to file system


How can I save the result from qconsole to output file. The output.txt will has name uri in each line below. I have over thousand of documents.

 Caltech.xml
 CGU.xml
 GMU.xml
 Hopkins.xml
 Georgetown.xml
 ....

let $uris:= cts:uris(
        (),
        (),
        cts:and-query(( cts:collection-query("/Universities/")))

    )

let $quote:=
   for $u in $uris
   return 
       fn:substring-after($u,"/Universities/")

let $output:=
text {
fn:concat(
    fn:string-join(($quote),","),
    "
"
 )

}  
return xdmp:save(fn:concat("/09122018/output.txt") ,$output) 

Solution

  • Don't string-join and concat to create one big string. Instead, hand in multiple strings as text nodes, wrapped in a document node that you pass into xdmp:save. You can easily handle a couple of million documents that way (provided you are willing to wait a minute). See also: https://stackoverflow.com/a/52005868/918496

    If you need to scale beyond that, look at Corb2, as suggested by Rob.

    HTH!