20

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 redirects.

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

4 Answers 4

33

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.

Sign up to request clarification or add additional context in comments.

4 Comments

YES! That works for CURL. Any idea why appending that to the URL while using Firefox/Futon seems to trip it up?
Updated with ideas about Firefox
... Bash is probably eating your double quotes before curl runs ... that was true in my case. On my terminal command line the curl command was not working. Then I used back-slash before my double-quotes and the problem got resolved. Also I needed to use back-slash before & character, too. Like this: ?startkey=\"ב\"\&endkey=\"ש\"
HOURS on a similar problem. When forming the URL to make a request to my update handler, the key must be in quotes, but not the value. Version 2.2.0. Method: 'PUT'. URL: 'testdata/_design/testDesigns/_update/setKeyValue/DOCID?key="hairColor"&value=purple' . If I put quotes around the value, they get carried over as escaped quotes in the database.
5

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\"

Comments

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

This works for me in cygwin

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.