如何在couchbase中区分

时间:2015-04-13 10:12:08

标签: couchbase couchbase-view

我想在cb中创建一个基于日期范围输入显示一些数据的视图。

我的问题是如何区分数据? 这是我的地图代码:

function (doc, meta) {
  if(!doc.clipGeneration.fromCache){
    var eiid = doc.clipGeneration.batchId;
    if (eiid == null){
        eiid = "API";
    }
    if (  !(doc.clipGeneration.externalId.indexOf("API_INTERVAL_TEST")>=0) )   {
    emit([doc.clipGeneration.clipStyle, eiid,doc.eventOccurenceTimeStamp[0], doc.eventOccurenceTimeStamp[1], doc.eventOccurenceTimeStamp[2],doc.eventOccurenceTimeStamp[3]], doc.insertRawTimestamp);
        emit([doc.clipGeneration.clipStyle, "ALL",doc.eventOccurenceTimeStamp[0], doc.eventOccurenceTimeStamp[1], doc.eventOccurenceTimeStamp[2],doc.eventOccurenceTimeStamp[3]], doc.insertRawTimestamp);
    emit([doc.eventOccurenceTimeStamp[0], doc.eventOccurenceTimeStamp[1], doc.eventOccurenceTimeStamp[2],doc.clipGeneration.clipStyle], doc.insertRawTimestamp);
    }
  }
}

reduce是_count,例如过滤器是:

startkey:[2015,1,1,null]

:[2015,1,31," \ uffff"]

输出符合日期范围的预期:

{"key":[2015,1,11,"5001188"],"value":1},
{"key":[2015,1,12,"100022"],"value":5},
{"key":[2015,1,12,"155"],"value":11},
{"key":[2015,1,13,"100022"],"value":9},
{"key":[2015,1,13,"155"],"value":6},
{"key":[2015,1,13,"5001159"],"value":1},
{"key":[2015,1,13,"5001190"],"value":3},
{"key":[2015,1,14,"100022"],"value":12},
{"key":[2015,1,14,"5001194"],"value":1},
{"key":[2015,1,15,"100022"],"value":11},
{"key":[2015,1,16,"100022"],"value":10},
{"key":[2015,1,18,"100022"],"value":8},
{"key":[2015,1,18,"5001096"],"value":6},
{"key":[2015,1,18,"5001194"],"value":3}

但是你可以看到" 100022"重复多次,我怎么能在sql中做出类似的东西,所以它只会显示一次?

由于

1 个答案:

答案 0 :(得分:0)

实际上没有办法让ID字段分明。你可以通过键减少,但只能减少整个键 - 所以[date,id]就是你的情况。您可以在N1QL中执行此操作,因为它具有与SQL类似的实际DISTINCT关键字,但目前仍在开发人员预览中。