保存后,Map功能不会执行

时间:2013-05-16 09:14:48

标签: javascript mapreduce couchdb

我正在创建下面的map函数chouchdb 1.3.0。如果我将它作为临时视图运行它可以正常工作,但是一旦我保存它就无法编译。

function(doc) {
    var datestamp = convert_date(doc["report"]["period"]);
    var report_suite = doc["report"]["reportSuite"]["id"];
    var segment = doc["report"]["segment_id"];
    emit([report_suite, segment, datestamp], [doc["report"]["elements"][0]["id"]]);
  }

function convert_date(date){
    var months = {"Jan": "01", "Feb": "02", "Mar": "03", "Apr": "04", "May": "05",    "Jun": "06", "Jul": "07", "Aug": "08", "Sep": "09", "Oct": "10", "Nov": "11", "Dec": "12" };
    var year = date.substring(13, 17);
    var month = months[date.substring(8,11)];
    var day = date.substring(5,7).replace(" ", "0");
    var datestamp = year + month + day;
    return datestamp;
}

错误消息是:“表达式不会对函数进行评估”

我用Google搜索并尝试失败:

  • 在功能
  • 周围放置括号
  • 内联convert_date函数

2 个答案:

答案 0 :(得分:2)

如果将convert_date函数放在map函数中,该怎么办?

  function(doc) {
    var convert_date = function(date) {
      var months = {"Jan": "01", "Feb": "02", "Mar": "03", "Apr": "04", "May": "05",    "Jun": "06", "Jul": "07", "Aug": "08", "Sep": "09", "Oct": "10", "Nov": "11", "Dec": "12" };
      var year = date.substring(13, 17);
      var month = months[date.substring(8,11)];
      var day = date.substring(5,7).replace(" ", "0");
      var datestamp = year + month + day;
      return datestamp;
    }
    var datestamp = convert_date(doc["report"]["period"]);
    var report_suite = doc["report"]["reportSuite"]["id"];
    var segment = doc["report"]["segment_id"];
    emit([report_suite, segment, datestamp], [doc["report"]["elements"][0]["id"]]);
  }

答案 1 :(得分:0)

好的,这很奇怪。我现在打开了实际的设计文档,复制了它并删除了所有其他功能,现在又重新开始了。