Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finding Your Data with Views > Find One > Might need to explain encoding for CURL #552

Open
oodavid opened this issue Mar 27, 2016 · 2 comments

Comments

@oodavid
Copy link

oodavid commented Mar 27, 2016

http://guide.couchdb.org/draft/views.html#one

Say we know the date of a blog post. To find a single document, we would use /blog/_design/docs/_view/by_date?key="2009/01/30 18:04:11" to get the “Biking” blog post. Remember that you can place whatever you like in the key parameter to the emit() function.

Again, just following along. I can't make it work to get just one document. Here's my successful request to get all docs:

$ curl http://127.0.0.1:5984/basic/_design/blog/_view/by_date
{"total_rows":3,"offset":0,"rows":[
{"id":"hello-world","key":"2009/01/15 15:52:20","value":"Hello World"},
{"id":"biking","key":"2009/01/30 18:04:11","value":"Biking"},
{"id":"bought-a-cat","key":"2009/02/17 21:13:39","value":"Bought a Cat"}
]}

And here's me failing to grab a single doc by key:

$ curl http://127.0.0.1:5984/basic/_design/blog/_view/by_date?key="2009/01/15 15:52:20"

$ curl http://127.0.0.1:5984/basic/_design/blog/_view/by_date?key="2009%2F01%2F15 15:52:20"
{"error":"bad_request","reason":"invalid_json"}

$ curl http://127.0.0.1:5984/basic/_design/blog/_view/by_date?key="2009%2F01%2F15%2015%3A52%3A20"
{"error":"bad_request","reason":"invalid_json"}

$ curl -v http://127.0.0.1:5984/basic/_design/blog/_view/by_date?key="2009/01/15 15:52:20"
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
> GET /basic/_design/blog/_view/bydate?key=2009/01/15 15:52:20 HTTP/1.1
> Host: 127.0.0.1:5984
> User-Agent: curl/7.42.0
> Accept: */*
> 
< HTTP/1.1 400 Bad Request
< Server: MochiWeb/1.0 (Any of you quaids got a smint?)
< Date: Sun, 27 Mar 2016 20:07:25 GMT
< Content-Length: 0
< 
* Connection #0 to host 127.0.0.1 left intact

Not sure if this is an issue with the documentation, or if I'm just being an idiot...

@oodavid
Copy link
Author

oodavid commented Mar 27, 2016

PS - I'm still using the "basic" database from an earlier chapter. But I'd still expect this to work as I can still get all the docs for that view....

@oodavid
Copy link
Author

oodavid commented Mar 27, 2016

Aha, I forgot to escape the quotations, this worked fine:

curl http://127.0.0.1:5984/basic/_design/blog/_view/by_date?key=?key=%222009/01/15%2015:52:20%22

I'll leave this issue open in case it needs documenting.

@oodavid oodavid changed the title Finding Your Data with Views > Find One > Example code fails Finding Your Data with Views > Find One > Might need to explain encoding for CURL Mar 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant