Reputation: 1048
I am inserting some xml documents from the UI in Marklogic Server and at the same time showing them in a list. I want to show the documents in a order. The document first inserted should come first in a list. Second document should come at second place and so on. But Marklogic is showing them randomly without any order.
Upvotes: 0
Views: 1123
Reputation: 908
You can order documents by data of last update:
(:If uri lexicone is enabled, else you can iterate by fn:collection():)
for $uri in cts:uris((), "document")
let $updated-date := xdmp:document-get-properties($uri, fn:QName("http://marklogic.com/cpf", "last-updated"))
order by $updated-date/text()
return $uri
There is another way, without using uri lexicon:
for $doc in fn:collection()
let $uri := xdmp:node-uri($doc)
let $updated-date := xdmp:document-get-properties($uri, fn:QName("http://marklogic.com/cpf", "last-updated"))
order by $updated-date/text()
return $uri
Upvotes: 0
Reputation: 305
The insert order is not persisted or preserved when working with MarkLogic Server. If you want your document's insert order to be preserved the data or the data's properties will need some value upon which the server can do an "order by" clause.
for $doc in fn:doc()
order by $doc//some-aspect-of-the-xml-structure
return
$doc
The documents are indeed independent from each-other in a "shared nothing" architecture. This helps MarkLogic run much faster than some relational database approaches where "rows" share membership and ordering in a "table" and as a result have trouble clustering efficiently.
Upvotes: 2