2014-01-25 28 views
1

我試圖從我的數據庫中獲取列表。這些文件看起來像:CouchDB列表函數拋出TypeError(點是未定義的)

{ 
"class": "lists", 
"collection": "symptoms", 
"order": "6", 
"en": "Headache", 
"_id": "9022034e7d5ecd0efab0762c5b7f0c04" 
} 

有任意數量的「集合」。

視圖函數返回一串對象的類中的「清單」:

// Emit lists 
exports.viewlist = { 
    map: function(doc) { 
    if (doc.class === 'lists') { 
     emit(
      doc.collection, { 
       order: doc.order, 
       name: doc.en 
      }); 
    } 
    } 
}; 

我寫了一個列表功能,以儘量過濾輸出,只是我想要的清單。

http://localhost:5984/dev/_design/emr/_list/viewlists/viewlist?l=symptoms 

{"error":"TypeError","reason":"{[{<<\"message\">>,<<\"point is undefined\">>},  
{<<\"fileName\">>,<<\"/usr/share/couchdb/server/main.js\">>}, 
{<<\"lineNumber\">>,1500},\n {<<\"stack\">>, 
<<\"(\\\"_design/emr\\\",[object Array], 
[object Array])@/usr/share/couchdb/server/main.js:1500\ 
()@/usr/share/couchdb/server/main.js:1562\ 
@/usr/share/couchdb/server/main.js:1573\ 
\">>}]}"} 

我想不通我要去哪裏錯在這裏:

exports.viewlist = function(head, req) { 
    var row; 
    start({ 
    code: 200, 
    headers: { 
     'Content-Type': 'text/json; charset=utf-8', 
    } 
}); 
while (row = getRow()) { 
    if (row.collection === req.l) { 
     send(JSON.stringify(row.value)); 
    } 
    } 
}; 

的CouchDB當我訪問列表的URL拋出一個錯誤。

+0

此問題剛剛在這裏得到解答:http://stackoverflow.com/a/21362699/3237351 – jun

回答

2

我也遇到了這個錯誤,並且導致它的原因,正如@PAO-pod在這裏暗示的Submitting form to couchDB through update handler not working,沒有在couchapp的設計文檔中正確定義你的exports。在我們的例子中,它是列表函數,無法調用,而是在couchdb日誌中顯示500錯誤,其中Type errorpoint is undefined

我們使用kanso,並在app.js中我們不需要列表文件。我們有:

module.exports = { 
    rewrites: require('./rewrites'), 
    views: require('./views'), 
    shows: require('./shows') 
}; 

將其更改爲以下解決了這個問題:

module.exports = { 
    rewrites: require('./rewrites'), 
    views: require('./views'), 
    shows: require('./shows') 
    lists: require('./lists'), 
}; 

我可以建議版主改變這個問題的標題包括point is undefined這是上面顯示出錯誤CouchDB日誌何時發生這種類型的錯誤,以幫助其他人更輕鬆地找到它?

相關問題