我想查询marklogic在最后3分钟内在集合中更新的文档。
我试图为需求编写一个结构化查询,但它只接受dateTime的硬编码值,而不是fn:current-dateTime()函数。下面是我试过的。
<query xmlns="http://marklogic.com/appservices/search">
<and-query>
<collection-query>
<uri>live</uri>
</collection-query>
<range-query type="xs:dateTime">
<element ns="" name="created-on"/>
<value>2019-06-10T10:36:14.002101Z</value>
<range-operator>GT</range-operator>
</range-query>
</and-query>
</query>我想像这样的事-
<query xmlns="http://marklogic.com/appservices/search">
<and-query>
<collection-query>
<uri>live</uri>
</collection-query>
<range-query type="xs:dateTime">
<element ns="" name="created-on"/>
<value>{fn:current-dateTime() - xs:dayTimeDuration("PT3M")}</value>
<range-operator>GT</range-operator>
</range-query>
</and-query>
</query>发布于 2019-06-12 16:23:32
可以使用表达语言在QueryMarklogic处理器的查询属性中以任何格式填充当前时间。
类似于:
<query xmlns="http://marklogic.com/appservices/search">
<and-query>
<collection-query>
<uri>live</uri>
</collection-query>
<range-query type="xs:dateTime">
<element ns="" name="created-on"/>
<value>${now():minus(180000):format('YYYY-MM-dd HH:mm:ss.SSS')}</value>
<range-operator>GT</range-operator>
</range-query>
</and-query>
</query>该表达式通过now()获取当前时间,通过minus()减去3分钟*60秒/ min * 1000毫秒/秒= 180000毫秒,然后以特定格式表示日期。您可以使用电码将该输出更改为您需要的任何输出。
https://stackoverflow.com/questions/56562001
复制相似问题