Couchbase视图出现问题并减少功能

时间:2020-05-11 23:43:48

标签: couchbase couchbase-view

我有bucketX桶这样的物体...。

{
  "type": "a",
  "nextEvent": "2020-02-14T12:21:46+00:00",
  "xid": 123
}

我想搜索这些文档以找到每个nextEvent的最新xid日期。

我为此创建了一个视图。这是我的地图功能:

function (doc, meta) {
  if (doc.type === 'a' && doc.nextEvent&& doc.xid) {
    let next= typeof doc.nextEvent === 'number' ? doc.nextEvent: ((new Date(doc.nextEvent)).getTime()) / 1000;
    emit(doc.xid, next);
  }
}

我有一个自定义的reduce函数来获取最新的nextEvent条目...。

function (key, values, rereduce) {
  const x= Array.isArray(key) ? key[0] : key;
  let max = values[0];
  for(i = 1; i < values.length; i++) {
    if(values[i] > max) {
      max = values[i]
    }
  }
  return max;
}

我能够根据需要查看和查询存储桶,但结果仅显示值。我需要使用存储在我的代码中的xid作为视图键。如何从视图查询中获取密钥?

0 个答案:

没有答案
相关问题