开发者

CouchDB view throwing invalid UTF-8 JSON error when using key, startkey

I have a VERY basic view defined in CouchDB:

function(doc) {
  if(doc.date && doc.erc) {
    emit(doc.date, doc.erc);
  }
}

It simply pulls ALL documents and sorts by dates.

I've tried appending

?startkey="2010-05-01"

to the URL and Futon just browser 开发者_如何学Pythonredirects.

I've tried using CURL as well:

curl -X GET http://localhost:5984/plots/_design/by_date/_view/by_date?startkey="2010-05-01"

That throws an error:

{"error":"bad_request","reason":"invalid UTF-8 JSON"}

What am I doing wrong? This should be a VERY basic thing.

Thanks, -Jim


CouchDB needs to see the double-quotes.

Bash is probably eating your double quotes before curl runs. Put the URL (double-quotes and all) in single quotes.

curl -X GET 'http://localhost:5984/plots/_design/by_date/_view/by_date?startkey="2010-05-01"'

That way, Bash will send the quotes to curl which will send them to CouchDB.

Possibly Firefox or Futon is eating your quotes too. Futon has a gray pointer icon in the upper-right. That links to the raw URL of the view. Try adding the startkey there. You can also input the double-quotes as %22.


I dont know whether you have already got the solution.. anyway for viewers like me who got the same error. This is the solution . I tried in windows

curl -X GET http://localhost:5984/plots/_design/by_date/_view/by_date?startkey=\"2010-05-01\"


curl xxx:xxxm@aaaa:5984/kitsi_arin/_design/arinDesign/_view/TestView2?key=\"Arindam\"

This works for me in cygwin


You can also use URL %codes, %22 gets converted to double quotes " by most fetch programs

curl -X GET http://localhost:5984/plots/_design/by_date/_view/by_date?startkey=%222010-05-01%22
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜