I am new to marklogic. Can anyone please provide me a script to get document name and XML file contents of the document, and also uploaded/created timestamp by passing attribute value.
2 Answers
In addition to the answer by @eric-bloch, if you did a search, you can determine the uri using fn:base-uri() or xdmp:node-uri(). For example like this:
for $d in cts:search(doc(), cts:and-query(()))[1 to 10]
return fn:base-uri($d)
Note: the empty and-query is a little trick to get all documents returned. The 1 to 10 predicate makes sure you don't get the entire database returned at once, but only the first ten. If you would add an order by on the last-modified property, you could get the ten oldest or newest documents this way.
This question is hard to understand. Documents in MarkLogic are identified by URI, not name. If you know the URI, then just do
doc($uri)
to get the contents. The last-modified time for a document is stored as document property, which you can get using the XPath properties axis like
doc($uri)/property::*:last-modified/string()
There are other ways to get the document properties, like the xdmp:document-properties() api call.