我有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
作为视图键。如何从视图查询中获取密钥?