使用CouchDB(1.6.1) List函数输出到csv文件

Using the CouchDB(1.6.1) List function to output to a csv file

我正在尝试掌握 principles/syntax 在 CouchDB 1.6.1 中使用列表函数将特定字段输出到 csv 文件。

我已经设置了一个简单的输出到 html,这似乎更容易做,而且效果很好。

我想做的是有一个列表功能需要的视图,从数据库中输出选定的字段并将数据输出到 csv 文件。

我似乎无法做到的是从视图输出中获取 'read' 特定字段的列表函数,我成功地获得了 html 输出。

视图函数看起来像这样:

function(doc){
emit({'A':doc.a, 'B':doc.b, 'C':doc.c.d  .....}, null);}

html 列表函数看起来像这样:

"function(head, req){
start({'headers': {
'Content-Type': 'text/html' }});
send('<html><body><table>');
send('<tr><th>A</th><th>B</th><th>C</th></tr>');
while(row=getRow()){
send(''.concat( '<tr>', '<td>' + toJSON(row.key.A) + '</td>','<td>' + toJSON(row.key.B) + '</td>','<td>' + toJSON(row.key.C) + '</td>', '</tr>' ));}
send('</table></body></html>');}"

同一视图的 csv 输出的类似列表函数应如下所示:

"function(head, req){
start({'headers': { 'Content-Type': 'text/csv' }});
send('A' +','+ 'B' +','+'C' + '\n');
while(row=getRow()){
send(''.concat( toJSON(row.key.A)  , toJSON(row.key.B) ,  toJSON(row.key.C) ));};}"

这导致“"error":"compilation_error","reason":"Expression does not eval to a function ...."

我已经尝试了 csv 函数的多种变体,除了一堆乱七八糟的格式不正确的文本外,都没有成功。

csv 列表函数的推荐起始点在某个网站上给出如下:

function (head, req) {
start({

    “headers”: {

      “Content-Type”: “text/csv”

     }

  });

send(‘Username, Name, Email\n’);

while(row = getRow()) {

    send(row.value.username+’,’+row.value.email+’,’+row.value.metadata.name+’\n’);

  }

} 

我根本无法让这个结构工作。

请就正确使用的语法提供一些意见。

我找到了指南here。 Oliver Kurowski 的幻灯片分享。

基本原则是:

"views": {
"byPrice": {
"map": "function(doc){emit(doc.price, [doc.make,doc.year]);};"
}
}
"lists": { 
"csv": "function(head,req){start({'headers':{'Content-Type':'text/csv'}});send('Make'+','+'Year'+','+'Price'+'\n');while(row=getRow()){send(row.value+','+row.key+'\n');}};"
}

它运行良好。

谢谢奥利弗。