简体   繁体   English

代码问题 - 试图列出 MarkLogic 目录中的文档

[英]Code issue - trying to list documents in MarkLogic directory

I'm trying to list documents in a few directories in a MarkLogic database.我正在尝试在 MarkLogic 数据库的几个目录中列出文档。

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.我是 XQuery 的新手,所以我只需要 30 秒的时间告诉我哪里出了问题以及如何解决。 As its in MarkLogic am unsure if that adds an extra layer complexity on top of it all, which I can't answer.由于它在 MarkLogic 中,我不确定这是否会增加额外的层复杂性,我无法回答。

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:我的代码如下 - 我要做的就是尝试使用 MarkLogic 查询控制台中的 XQuery 返回 MarkLogic 9 数据库目录/Engine/Cooling/Radiators中的所有文档:

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.我已经花时间在 XQuery 编码上搜索网站。 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.我意识到这是一个简单的问题,但我被困住了,需要那些既编码这些东西又可能在 MarkLogic 中工作的人的帮助。

You have a slight typeo.你有一个轻微的打字。 XQuery variables need the $ preceding the variable name. XQuery 变量需要在变量名前加上$

Change d$ to $d :d$更改为$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:您可以使用 XPath 缩短代码并消除 for 循环和变量:

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

or by using a simple map operator :或使用简单的 map 运算符

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM