steve
steve

Reputation: 443

Code issue - trying to list documents in MarkLogic directory

I'm trying to list documents in a few directories in a MarkLogic database.

I am new to XQuery, so I just need 30 seconds of someone's time to tell me what's wrong and how to fix. As its in MarkLogic am unsure if that adds an extra layer complexity on top of it all, which I can't answer.

My code is below - all I'm trying to do is trying to return all docs in the MarkLogic 9 database directory /Engine/Cooling/Radiators using an XQuery in MarkLogic Query Console :

for d$ in xdmp:directory("/Engine/Cooling/Radiators","1")
return xdmp:node-uri(d$)

It returns

 "XDMP-UNEXPECTED ( err:XPST0003) Unexpected token sysntax error, unexpected QName_, expecting $end of SemiColon_"

I have spent time trawling sites on XQuery coding already. I realize its a simple-ish question, but I'm stuck and need help from people who both code this stuff and probably work in MarkLogic.

Upvotes: 1

Views: 92

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66781

You have a slight typeo. XQuery variables need the $ preceding the variable name.

Change d$ to $d:

for $d in xdmp:directory("/Engine/Cooling/Radiators","1")
return xdmp:node-uri($d)

And you could shorten the code and eliminate the for loop and the variable by using XPath:

xdmp:directory("/Engine/Cooling/Radiators","1")/xdmp:node-uri(.)

or by using a simple map operator:

xdmp:directory("/","1") ! xdmp:node-uri(.)

Upvotes: 3

Related Questions