【问题标题】:Xquery in Marklogic to return datetime less than 1 month from the current dateMarklogic 中的 Xquery 返回距当前日期不到 1 个月的日期时间
【发布时间】:2021-09-03 20:32:55
【问题描述】:

Delete documents less than 30 days in Marklogic Xquery

我在互联网上搜索如何返回距当前日期不到 1 个月的文件,我找到了上面的链接。由于我正在使用的元素没有范围索引

let $currentdt := fn:current-dateTime()
let $amonthAgo := $currentdt- xs:yearMonthDuration("P1M")
cts:search(doc(), 
  cts:element-query(xs:QName("myDateTimeField"), cts:true-query())
)[.//myDateTimeField[xs:dateTime(.) eq $amonthAgo]]

什么都不返回。


我有示例值,例如

2021-05-18T06:32:34.761729-04:00
2021-05-15T06:32:34.761729-04:00
2021-03-19T06:32:34.761729-04:00
2021-06-15T06:32:34.761729-04:00

TIA!

【问题讨论】:

    标签: xquery marklogic


    【解决方案1】:

    除了 FLWOR 表达式缺少 return 之外,您还要求恰好一个月前的所有匹配项,因为您在比较中使用了 eq。如果您想查找不到一个月的文档,您希望它们的日期在恰好一个月前的时间点之后(即$amonthAgo)。您可以将谓词更正并简化为xs:dateTime(myDateTimeField) gt $amonthAgo。这是一个适用于我的独立示例:

    declare context item := document {
      <doc>
        <e id="1">
          <myDateTimeField>2021-05-18T06:32:34.761729-04:00</myDateTimeField>
        </e>
        <e id="2">
          <myDateTimeField>2021-05-15T06:32:34.761729-04:00</myDateTimeField>
        </e>
        <e id="3">
          <myDateTimeField>2021-03-19T06:32:34.761729-04:00</myDateTimeField>
        </e>
        <e id="4">
          <myDateTimeField>2021-06-15T06:32:34.761729-04:00</myDateTimeField>
        </e>
      </doc>
    };
    let $currentdt := fn:current-dateTime()
    let $amonthAgo := $currentdt - xs:yearMonthDuration("P1M")
    return //e[xs:dateTime(myDateTimeField) gt $amonthAgo]
    

    结果(2021-06-19):

    <e id="4">
      <myDateTimeField>2021-06-15T06:32:34.761729-04:00</myDateTimeField>
    </e>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-14
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多