简体   繁体   中英

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.

I found this line in stackoverflow: How to get total number of documents in Marklogic database?

...which will get the count of documents in a database. I'm not sure how to modify this to list all document URIs.

Also given a document URI I wanted to see if it exists in the database?

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. I am new to marklogic, can someone help me on this?

If all you need to get from the database is the list of uri use cts:uris() . It will just return the uri and won't require the full documents to be return like fn:doc() would. If the uri lexicon is set to true at the database level the it will just be going off on in an memory index.

If you want to check if a document exists use

fn:doc-available("uri of document")

1- If you have used collection then you can use

for $each in collection("collection-name") return fn:document-uri($each)

2- If you have same directory structure then use

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.

fn:doc() will return a list of all documents if no parameter is given, or return the document if a URI is given. So to list all URIs in a database, use:

for $x in fn:doc()
   return fn:document-uri($x)

See fn:doc for more. If you want to check whether a document exists, just use fn:doc() with a URI:

fn:doc("/example/uri.xml")

查找文档是否存在的另一个选项:

xdmp:exists(doc("uri.xml"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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