Couchbase 获取给定日期范围内的文件

Couchbase get the documents within given date range

这是我存储桶中的文档结构。

 {
  "_class": "com.link.pojo.Event",
  "year": "2015",
  "start": 1440115200000,
  "name": "129811",
  "domain": "500015$Exhibition",
  "sporttype": "Indoor",
  "eventtype": "Exhibition",
  "end": 1440151199000,
}

此处start表示事件开始日期,类型为util Date。示例日期格式值为 2015-08-10T09:45:00.000+0000 现在我想使用 couchbase 视图获取从当前日期开始的所有文档。这是我试图得到它的方式,什么是

// Create the CouchbaseClient Query object & Pass the time range to fetch events.
Query query = new Query();
// Filter on the start date and this value has to be within below given range params.
query.setIncludeDocs(true);
query.setDescending(true);
query.setInclusiveEnd(true);
query.setRange(ComplexKey.of(""), ComplexKey.of(""));
List<Event> eventList = `eventService.getEventsByCurrentDate(query);`

我应该在 query.setRange(); 函数中传递哪些值。我需要实现的视图是什么?

function (doc, meta) {
  if (doc._class == "com.link.pojo.Event") {
    emit(doc.start, null);
  }
}

你做错了:]

查询只是一种过滤视图的某些结果的方法。因此,首先定义一个视图 - 然后确定您需要使用哪个查询来获得您需要的内容。

  1. 首先在 Couchbase 中创建视图 UI。

  2. 然后查看视图的结果 - 再次使用 couchbase UI。应该有一个 link 您可以单击以在浏览器的新选项卡中查看视图的结果。

  3. 然后您可以编辑 url 至 "query" 您的视图结果。添加 "&key=123 以获取该密钥。SetRange 仅表示 - "get the keys that fall in that range of numbers".

  4. 在您的情况下,由于您的视图发出 "start" 字段,因此您的键(或范围)必须采用 same 格式.所以像 &key=1440115200000

希望对您有所帮助。