Find binary documents that have been recently modified.
Applies to MarkLogic versions 7+
xquery version "1.0-ml"; declare namespace qry = "https://marklogic.com/cts/query"; let $binary-term := xdmp:plan(/binary())//qry:term-query/qry:key/text() let $query-start := (fn:current-dateTime() - xs:dayTimeDuration("P1D")) let $query-stop := fn:current-dateTime() let $query := cts:and-query(( cts:properties-query( cts:and-query(( cts:element-range-query(xs:QName("prop:last-modified"), ">", $query-start), cts:element-range-query(xs:QName("prop:last-modified"), "<", $query-stop) )) ), cts:term-query($binary-term) )) return ( text{"Estimate:", xdmp:estimate(cts:search(fn:doc(), $query))}, cts:uris((), ("limit=100"), $query) )
Required Privileges:
Required Indexes:
Recently-modified binaries can be found if the “maintain last modified” option on the target database is active. You must also have a dateTime range index set up on prop:last-modified, so that the cts:element-range-query
s will work.
The xs:dayTimeDuration
chosen for $query-start
defines what “recent” means in this case. Notice that the last-modified date is stored in a property fragment, so this recipe uses a cts:properties-query
to look for it.
The recipe returns an estimate of the number of recently-modified binaries, as well as the URIs of the first 100. We can count on the estimate to be accurate, as the query is targeting indexes.
By continuing to use this website you are giving consent to cookies being used in accordance with the MarkLogic Privacy Statement.