我试图掌握在CouchDB 1.6.1中使用列表函数将特定字段输出到csv文件的原理/语法。
我已经设置了一个简单的html输出,这似乎更容易做到,效果很好。
view函数如下所示:
function(doc){
emit({'A':doc.a, 'B':doc.b, 'C':doc.c.d .....}, null);}
"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列表功能的推荐起点如下:
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â);
}
}
我根本无法让这个结构工作。
如果您能提供正确的语法,我将不胜感激。