如何在特定日期后获取记录 [英] How to fetch records after a particular date

查看:132
本文介绍了如何在特定日期后获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取字段" effectiveDateOfAction "大于2017年10月的记录.请找到以下3条记录.

I am trying to fetch the records that has the "effectiveDateOfAction" field greater than Oct'2017. Please find the below 3 records.

{
 "_id": "TRAN001",
 "_rev": "13-59a53069c1ebd6ecfc23ca1dea0ba28f",
 "effectiveDateOfAction": "10-30-2018",
 "employeeName": "Kumar,Vinoth",
 "transferReportID": "TRAN001",
 "~version": "76:0"
}

{
 "_id": "TRAN001",
 "_rev": "12-c320c61168f5d6d020f971124cb395f2",
 "effectiveDateOfAction": "05-10-2018",
 "employeeName": "Vinoth",
 "transferReportID": "TRAN002",
 "~version": "77:0"
}

{
 "_id": "TRAN003",
 "_rev": "16-567a15e9ea7e2349d4c24816e7eafda3",
 "effectiveDateOfAction": "10-20-2017",
 "employeeName": "Kumar",
 "transferReportID": "TRAN003",
 "~version": "78:0"
}

请在下面尝试的查询中查找.我正在使用Project Fauxton进行检查.

Please find my query below which i tried.I am checking using Project Fauxton.

{"selector": {"$and": [{"transferReportID": {"$ne": null}},{"effectiveDateOfAction": {"$gt": "10-31-2017"}}]}}

请帮助我获取正确的查询.

Please help me getting the correct query.

推荐答案

由于JSON中没有本机日期类型,因此以在查询时有意义的格式存储日期非常重要.当为美国受众群体呈现日期时,月-日-年"格式可能会很有用,但查询的意义不大.

As there is no native date type in JSON, it's important to store dates in a format that makes sense at query time. The "Month-Day-Year" format may be useful when rendering dates for a US audience but it makes little sense for querying.

我建议使用"YYYY-MM-DD"格式,例如"2018-10-30".这样可以存储与以前相同的数据,但排序顺序恰好是按日期顺序进行的,因为年份长于几个月,而月份长于几天.

I would suggest the "YYYY-MM-DD" format e.g "2018-10-30". This stores the same data as before but the sort order happens to be in date order, because years are longer than months and months are longer than days.

然后您可以使用"$ gte"运算符来查询:

You can then use a query using the "$gte" operator:

{
  "selector": {
    "effectiveDateOfAction": {
      "$gte": "2018-10-01"
     }
  }
}

读取为获取其'effectiveDateOfAction'字段大于或等于2018年10月1日的文档".

This reads as "fetch documents whose 'effectiveDateOfAction' field is greater than or equal to 1st October 2018'.

请参见此博客文章有关如何在CouchDB中存储和查询日期的信息.

See this blog post on how to store and query dates in CouchDB.

这篇关于如何在特定日期后获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆