[英]How to get list of document uri names from a database marklogic?
Hey I am trying to get the list of all document names /uri from a given MarkLogic database. 嘿我想从给定的MarkLogic数据库中获取所有文档名称/ uri的列表。
I found this line in stackoverflow: How to get total number of documents in Marklogic database? 我在stackoverflow中找到了这一行: 如何获取Marklogic数据库中的文档总数?
...which will get the count of documents in a database. ...将获取数据库中的文档计数。 I'm not sure how to modify this to list all document URIs.
我不知道如何修改它以列出所有文档URI。
Also given a document URI I wanted to see if it exists in the database? 还给出了一个文档URI,我想看看它是否存在于数据库中?
I tried the following, but couldn't achieve the same 我试过以下,但无法实现同样的目标
for $x in xdmp:directory("/myDirectory/", "1")
return
fn:document-uri($x)
I need a Xquery command just like this. 我需要一个像这样的Xquery命令。 I am new to marklogic, can someone help me on this?
我是marklogic的新手,有人可以帮我吗?
If all you need to get from the database is the list of uri use cts:uris()
. 如果您需要从数据库中获取所有内容,请使用uri列表
cts:uris()
。 It will just return the uri and won't require the full documents to be return like fn:doc()
would. 它只会返回uri,并且不需要像
fn:doc()
那样返回完整的文档。 If the uri lexicon is set to true at the database level the it will just be going off on in an memory index. 如果uri词典在数据库级别设置为true,那么它将在内存索引中启动。
If you want to check if a document exists use 如果要检查文档是否存在,请使用
1- If you have used collection then you can use 1-如果您使用过集合,那么您可以使用
for $each in collection("collection-name") return fn:document-uri($each)
2- If you have same directory structure then use 2-如果您有相同的目录结构,请使用
for $each in xdmp:directory("/myDirectory/", "infinity") return fn:document-uri($each)
3- If you have not used any of the above case, you can use cts:uris()
Please note in order to use cts:uris(), URI Lexicon
needs to be enabled. 3-如果你没有使用上述任何一种情况,你可以使用
cts:uris()
请注意为了使用cts:uris(), URI Lexicon
需要启用cts:uris(), URI Lexicon
。
fn:doc() will return a list of all documents if no parameter is given, or return the document if a URI is given. 如果没有给出参数,则fn:doc()将返回所有文档的列表,如果给出了URI,则返回文档。 So to list all URIs in a database, use:
因此,要列出数据库中的所有URI,请使用:
for $x in fn:doc()
return fn:document-uri($x)
See fn:doc for more. 有关更多信息,请参阅fn:doc 。 If you want to check whether a document exists, just use
fn:doc()
with a URI: 如果要检查文档是否存在,只需使用带有URI的
fn:doc()
:
fn:doc("/example/uri.xml")
查找文档是否存在的另一个选项:
xdmp:exists(doc("uri.xml"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.