couchdb view not responding as expected
I have couchdb 0.10 installed on Ubuntu 10.04. I have this view:
function(doc) {
if (doc.type == "transaction") {
emit(doc.invoice_id, {id: doc._id, time: doc.time, user_id:doc.user_id});
}
}
I call it through a get with key=247 parameter specified:
http://127.0.0.1:5984/test/_design/sfCouch/_view/f开发者_StackOverflowind_by_invoice_id?key=247
In the db I have a document matching invoice_id = 247:
{
"_id": "1357b381d8c22aa193f42de54e400d16",
"_rev": "2-778ea588fa449851bbab6cfa9fa91bfa",
"type": "transaction",
"user_id": "1",
"invoice_id": "247",
"time": 1303895611.37
}
but no rows are given back from the view:
{"total_rows":4,"offset":1,"rows":[]}
this is my design document:
{
"_id": "_design/sfCouch",
"_rev": "11-95c82a9d562b3aa1470a02de943f49db",
"language": "javascript",
"views": {
"find_by_invoice_id": {
"map": "function(doc) {\u000d\u000a if (doc.type == \"transaction\") {\u000d\u000a emit(doc.invoice_id, {id: doc._id, time: doc.time, user_id:doc.user_id});\u000d\u000a }\u000d\u000a}"
}
}
}
Am I missing something?
As the key invoice_id
is a string you need to specify the key as a JSON encoded string too.
Try:
http://127.0.0.1:5984/test/_design/sfCouch/_view/find_by_invoice_id?key=%22247%22
(the %22 is a URL Encoded " sign)
If that too fails can you post the output of:
http://127.0.0.1:5984/test/_design/sfCouch/_view/find_by_invoice_id
精彩评论